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

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

Pull bulk of gpio updates from Linus Walleij:
"A pretty big chunk of changes this time, but it has all been on
rotation in linux-next and had some testing. Of course there will be
some amount of fixes on top...

- Merged in a branch of irqchip changes from Thomas Gleixner: we need
to have new callbacks from the irqchip to determine if the GPIO
line will be eligible for IRQs, and this callback must be able to
say "no". After some thinking I got the branch from tglx and have
switched all current users over to use this.

- Based on tglx patches, we have added some generic irqchip helpers
in the gpiolib core. These will help centralize code when GPIO
drivers have simple chained/cascaded IRQs. Drivers will still
define their irqchip vtables, but the gpiolib core will take care
of irqdomain set-up, mapping from local offsets to Linux irqs, and
reserve resources by marking the GPIO lines for IRQs.

- Initially the PL061 and Nomadik GPIO/pin control drivers have been
switched over to use the new gpiochip-to-irqchip infrastructure
with more drivers expected for the next kernel cycle. The
factoring of just two drivers still makes it worth it so it is
already a win.

- A new driver for the Synopsys DesignWare APB GPIO block.

- Modify the DaVinci GPIO driver to be reusable also for the new TI
Keystone architecture.

- A new driver for the LSI ZEVIO SoCs.

- Delete the obsolte tnetv107x driver.

- Some incremental work on GPIO descriptors: have
gpiod_direction_output() use a logical level, respecting assertion
polarity through ACTIVE_LOW flags, adding gpiod_direction_output_raw()
for the case where you want to set that very value. Add
gpiochip_get_desc() to fetch a GPIO descriptor from a specific
offset on a certain chip inside driver code.

- Switch ACPI GPIO code over to using gpiochip_get_desc() and get rid
of gpio_to_desc().

- The ACPI GPIO event handling code has been reworked after
encountering an actual real life implementation.

- Support for ACPI GPIO operation regions.

- Generic GPIO chips can now be assigned labels/names from platform
data.

- We now clamp values returned from GPIO drivers to the boolean [0,1]
range.

- Some improved documentation on how to use the polarity flag was
added.

- a large slew of incremental driver updates and non-critical fixes.
Some targeted for stable"

* tag 'gpio-v3.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (80 commits)
gpio: rcar: Add helper variable dev = &pdev->dev
gpio-lynxpoint: force gpio_get() to return "1" and "0" only
gpio: unmap gpio irqs properly
pch_gpio: set value before enabling output direction
gpio: moxart: Actually set output state in moxart_gpio_direction_output()
gpio: moxart: Avoid forward declaration
gpio: mxs: Allow for recursive enable_irq_wake() call
gpio: samsung: Add missing "break" statement
gpio: twl4030: Remove redundant assignment
gpio: dwapb: correct gpio-cells in binding document
gpio: iop: fix devm_ioremap_resource() return value checking
pinctrl: coh901: convert driver to use gpiolib irqchip
pinctrl: nomadik: convert driver to use gpiolib irqchip
gpio: pl061: convert driver to use gpiolib irqchip
gpio: add IRQ chip helpers in gpiolib
pinctrl: nomadik: factor in platform data container
pinctrl: nomadik: rename secondary to latent
gpio: Driver for SYSCON-based GPIOs
gpio: generic: Use platform_device_id->driver_data field for driver flags
pinctrl: coh901: move irq line locking to resource callbacks
...

+2416 -986
+17
Documentation/devicetree/bindings/gpio/cirrus,clps711x-mctrl-gpio.txt
··· 1 + * ARM Cirrus Logic CLPS711X SYSFLG1 MCTRL GPIOs 2 + 3 + Required properties: 4 + - compatible: Should contain "cirrus,clps711x-mctrl-gpio". 5 + - gpio-controller: Marks the device node as a gpio controller. 6 + - #gpio-cells: Should be two. The first cell is the pin number and 7 + the second cell is used to specify the gpio polarity: 8 + 0 = Active high, 9 + 1 = Active low. 10 + 11 + Example: 12 + sysgpio: sysgpio { 13 + compatible = "cirrus,ep7312-mctrl-gpio", 14 + "cirrus,clps711x-mctrl-gpio"; 15 + gpio-controller; 16 + #gpio-cells = <2>; 17 + };
+23 -2
Documentation/devicetree/bindings/gpio/gpio-davinci.txt
··· 1 - Davinci GPIO controller bindings 1 + Davinci/Keystone GPIO controller bindings 2 2 3 3 Required Properties: 4 - - compatible: should be "ti,dm6441-gpio" 4 + - compatible: should be "ti,dm6441-gpio", "ti,keystone-gpio" 5 5 6 6 - reg: Physical base address of the controller and the size of memory mapped 7 7 registers. 8 8 9 9 - gpio-controller : Marks the device node as a gpio controller. 10 + 11 + - #gpio-cells : Should be two. 12 + - first cell is the pin number 13 + - second cell is used to specify optional parameters (unused) 10 14 11 15 - interrupt-parent: phandle of the parent interrupt controller. 12 16 ··· 31 27 gpio: gpio@1e26000 { 32 28 compatible = "ti,dm6441-gpio"; 33 29 gpio-controller; 30 + #gpio-cells = <2>; 34 31 reg = <0x226000 0x1000>; 35 32 interrupt-parent = <&intc>; 36 33 interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH ··· 43 38 ti,davinci-gpio-unbanked = <0>; 44 39 interrupt-controller; 45 40 #interrupt-cells = <2>; 41 + }; 42 + 43 + leds { 44 + compatible = "gpio-leds"; 45 + 46 + led1 { 47 + label = "davinci:green:usr1"; 48 + gpios = <&gpio 10 GPIO_ACTIVE_HIGH>; 49 + ... 50 + }; 51 + 52 + led2 { 53 + label = "davinci:red:debug1"; 54 + gpios = <&gpio 11 GPIO_ACTIVE_HIGH>; 55 + ... 56 + }; 46 57 };
+16
Documentation/devicetree/bindings/gpio/gpio-zevio.txt
··· 1 + Zevio GPIO controller 2 + 3 + Required properties: 4 + - compatible: Should be "lsi,zevio-gpio" 5 + - reg: Address and length of the register set for the device 6 + - #gpio-cells: Should be two. The first cell is the pin number and the 7 + second cell is used to specify optional parameters (currently unused). 8 + - gpio-controller: Marks the device node as a GPIO controller. 9 + 10 + Example: 11 + gpio: gpio@90000000 { 12 + compatible = "lsi,zevio-gpio"; 13 + reg = <0x90000000 0x1000>; 14 + gpio-controller; 15 + #gpio-cells = <2>; 16 + };
+52 -8
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". Exact 16 + GPIO properties should be named "[<name>-]gpios". The exact 17 17 meaning of each gpios property must be documented in the device tree 18 18 binding for each device. 19 19 20 - For example, the following could be used to describe gpios pins to use 20 + For example, the following could be used to describe GPIO pins used 21 21 as chip select lines; with chip selects 0, 1 and 3 populated, and chip 22 22 select 2 left empty: 23 23 ··· 44 44 Exact meaning of each specifier cell is controller specific, and must 45 45 be documented in the device tree binding for the device. 46 46 47 - Example of the node using GPIOs: 47 + Example of a node using GPIOs: 48 48 49 49 node { 50 50 gpios = <&qe_pio_e 18 0>; 51 51 }; 52 52 53 53 In this example gpio-specifier is "18 0" and encodes GPIO pin number, 54 - and empty GPIO flags as accepted by the "qe_pio_e" gpio-controller. 54 + and GPIO flags as accepted by the "qe_pio_e" gpio-controller. 55 + 56 + 1.1) GPIO specifier best practices 57 + ---------------------------------- 58 + 59 + A gpio-specifier should contain a flag indicating the GPIO polarity; active- 60 + high or active-low. If it does, the follow best practices should be followed: 61 + 62 + The gpio-specifier's polarity flag should represent the physical level at the 63 + GPIO controller that achieves (or represents, for inputs) a logically asserted 64 + value at the device. The exact definition of logically asserted should be 65 + defined by the binding for the device. If the board inverts the signal between 66 + the GPIO controller and the device, then the gpio-specifier will represent the 67 + opposite physical level than the signal at the device's pin. 68 + 69 + When the device's signal polarity is configurable, the binding for the 70 + device must either: 71 + 72 + a) Define a single static polarity for the signal, with the expectation that 73 + any software using that binding would statically program the device to use 74 + that signal polarity. 75 + 76 + The static choice of polarity may be either: 77 + 78 + a1) (Preferred) Dictated by a binding-specific DT property. 79 + 80 + or: 81 + 82 + a2) Defined statically by the DT binding itself. 83 + 84 + In particular, the polarity cannot be derived from the gpio-specifier, since 85 + that would prevent the DT from separately representing the two orthogonal 86 + concepts of configurable signal polarity in the device, and possible board- 87 + level signal inversion. 88 + 89 + or: 90 + 91 + b) Pick a single option for device signal polarity, and document this choice 92 + in the binding. The gpio-specifier should represent the polarity of the signal 93 + (at the GPIO controller) assuming that the device is configured for this 94 + particular signal polarity choice. If software chooses to program the device 95 + to generate or receive a signal of the opposite polarity, software will be 96 + responsible for correctly interpreting (inverting) the GPIO signal at the GPIO 97 + controller. 55 98 56 99 2) gpio-controller nodes 57 100 ------------------------ 58 101 59 - Every GPIO controller node must both an empty "gpio-controller" 60 - property, and have #gpio-cells contain the size of the gpio-specifier. 102 + Every GPIO controller node must contain both an empty "gpio-controller" 103 + property, and a #gpio-cells integer property, which indicates the number of 104 + cells in a gpio-specifier. 61 105 62 106 Example of two SOC GPIO banks defined as gpio-controller nodes: 63 107 64 108 qe_pio_a: gpio-controller@1400 { 65 - #gpio-cells = <2>; 66 109 compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank"; 67 110 reg = <0x1400 0x18>; 68 111 gpio-controller; 112 + #gpio-cells = <2>; 69 113 }; 70 114 71 115 qe_pio_e: gpio-controller@1460 { 72 - #gpio-cells = <2>; 73 116 compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank"; 74 117 reg = <0x1460 0x18>; 75 118 gpio-controller; 119 + #gpio-cells = <2>; 76 120 }; 77 121 78 122 2.1) gpio- and pin-controller interaction
+60
Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt
··· 1 + * Synopsys DesignWare APB GPIO controller 2 + 3 + Required properties: 4 + - compatible : Should contain "snps,dw-apb-gpio" 5 + - reg : Address and length of the register set for the device. 6 + - #address-cells : should be 1 (for addressing port subnodes). 7 + - #size-cells : should be 0 (port subnodes). 8 + 9 + The GPIO controller has a configurable number of ports, each of which are 10 + represented as child nodes with the following properties: 11 + 12 + Required properties: 13 + - compatible : "snps,dw-apb-gpio-port" 14 + - gpio-controller : Marks the device node as a gpio controller. 15 + - #gpio-cells : Should be two. The first cell is the pin number and 16 + the second cell is used to specify the gpio polarity: 17 + 0 = active high 18 + 1 = active low 19 + - reg : The integer port index of the port, a single cell. 20 + 21 + Optional properties: 22 + - interrupt-controller : The first port may be configured to be an interrupt 23 + controller. 24 + - #interrupt-cells : Specifies the number of cells needed to encode an 25 + interrupt. Shall be set to 2. The first cell defines the interrupt number, 26 + the second encodes the triger flags encoded as described in 27 + Documentation/devicetree/bindings/interrupts.txt 28 + - interrupt-parent : The parent interrupt controller. 29 + - interrupts : The interrupt to the parent controller raised when GPIOs 30 + generate the interrupts. 31 + - snps,nr-gpios : The number of pins in the port, a single cell. 32 + 33 + Example: 34 + 35 + gpio: gpio@20000 { 36 + compatible = "snps,dw-apb-gpio"; 37 + reg = <0x20000 0x1000>; 38 + #address-cells = <1>; 39 + #size-cells = <0>; 40 + 41 + porta: gpio-controller@0 { 42 + compatible = "snps,dw-apb-gpio-port"; 43 + gpio-controller; 44 + #gpio-cells = <2>; 45 + snps,nr-gpios = <8>; 46 + reg = <0>; 47 + interrupt-controller; 48 + #interrupt-cells = <2>; 49 + interrupt-parent = <&vic1>; 50 + interrupts = <0>; 51 + }; 52 + 53 + portb: gpio-controller@1 { 54 + compatible = "snps,dw-apb-gpio-port"; 55 + gpio-controller; 56 + #gpio-cells = <2>; 57 + snps,nr-gpios = <8>; 58 + reg = <1>; 59 + }; 60 + };
+1
Documentation/gpio/consumer.txt
··· 154 154 void gpiod_set_raw_value(struct gpio_desc *desc, int value) 155 155 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) 156 156 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) 157 + int gpiod_direction_output_raw(struct gpio_desc *desc, int value) 157 158 158 159 The active-low state of a GPIO can also be queried using the following call: 159 160
+35
Documentation/gpio/driver.txt
··· 62 62 requested as GPIOs. They can use gpiochip_is_requested(), which returns either 63 63 NULL or the label associated with that GPIO when it was requested. 64 64 65 + 66 + GPIO drivers providing IRQs 67 + --------------------------- 68 + It is custom that GPIO drivers (GPIO chips) are also providing interrupts, 69 + most often cascaded off a parent interrupt controller, and in some special 70 + cases the GPIO logic is melded with a SoC's primary interrupt controller. 71 + 72 + The IRQ portions of the GPIO block are implemented using an irqchip, using 73 + the header <linux/irq.h>. So basically such a driver is utilizing two sub- 74 + systems simultaneously: gpio and irq. 75 + 76 + It is legal for any IRQ consumer to request an IRQ from any irqchip no matter 77 + if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and 78 + irq_chip are orthogonal, and offering their services independent of each 79 + other. 80 + 81 + gpiod_to_irq() is just a convenience function to figure out the IRQ for a 82 + certain GPIO line and should not be relied upon to have been called before 83 + the IRQ is used. 84 + 85 + So always prepare the hardware and make it ready for action in respective 86 + callbacks from the GPIO and irqchip APIs. Do not rely on gpiod_to_irq() having 87 + been called first. 88 + 89 + This orthogonality leads to ambiguities that we need to solve: if there is 90 + competition inside the subsystem which side is using the resource (a certain 91 + GPIO line and register for example) it needs to deny certain operations and 92 + keep track of usage inside of the gpiolib subsystem. This is why the API 93 + below exists. 94 + 95 + 65 96 Locking IRQ usage 66 97 ----------------- 67 98 Input GPIOs can be used as IRQ signals. When this happens, a driver is requested ··· 104 73 is released: 105 74 106 75 void gpiod_unlock_as_irq(struct gpio_desc *desc) 76 + 77 + When implementing an irqchip inside a GPIO driver, these two functions should 78 + typically be called in the .startup() and .shutdown() callbacks from the 79 + irqchip.
+7
MAINTAINERS
··· 1928 1928 S: Supported 1929 1929 F: drivers/scsi/bnx2i/ 1930 1930 1931 + BROADCOM KONA GPIO DRIVER 1932 + M: Markus Mayer <markus.mayer@linaro.org> 1933 + L: bcm-kernel-feedback-list@broadcom.com 1934 + S: Supported 1935 + F: drivers/gpio/gpio-bcm-kona.c 1936 + F: Documentation/devicetree/bindings/gpio/gpio-bcm-kona.txt 1937 + 1931 1938 BROADCOM SPECIFIC AMBA DRIVER (BCMA) 1932 1939 M: Rafał Miłecki <zajec5@gmail.com> 1933 1940 L: linux-wireless@vger.kernel.org
+35 -5
drivers/gpio/Kconfig
··· 55 55 def_bool y 56 56 depends on ACPI 57 57 58 + config GPIOLIB_IRQCHIP 59 + bool 60 + 58 61 config DEBUG_GPIO 59 62 bool "Debug GPIO calls" 60 63 depends on DEBUG_KERNEL ··· 131 128 help 132 129 Say yes here to support basic platform_device memory-mapped GPIO controllers. 133 130 131 + config GPIO_DWAPB 132 + tristate "Synopsys DesignWare APB GPIO driver" 133 + select GPIO_GENERIC 134 + select GENERIC_IRQ_CHIP 135 + depends on OF_GPIO 136 + help 137 + Say Y or M here to build support for the Synopsys DesignWare APB 138 + GPIO block. 139 + 134 140 config GPIO_IT8761E 135 141 tristate "IT8761E GPIO support" 136 142 depends on X86 # unconditional access to IO space. ··· 156 144 def_bool y 157 145 depends on ARCH_EP93XX 158 146 select GPIO_GENERIC 147 + 148 + config GPIO_ZEVIO 149 + bool "LSI ZEVIO SoC memory mapped GPIOs" 150 + depends on ARM && OF_GPIO 151 + help 152 + Say yes here to support the GPIO controller in LSI ZEVIO SoCs. 159 153 160 154 config GPIO_MM_LANTIQ 161 155 bool "Lantiq Memory mapped GPIOs" ··· 246 228 config GPIO_PL061 247 229 bool "PrimeCell PL061 GPIO support" 248 230 depends on ARM_AMBA 249 - select GENERIC_IRQ_CHIP 231 + select IRQ_DOMAIN 232 + select GPIOLIB_IRQCHIP 250 233 help 251 234 Say yes here to support the PrimeCell PL061 GPIO device 252 235 ··· 294 275 Say yes here to support the STA2x11/ConneXt GPIO device. 295 276 The GPIO module has 128 GPIO pins with alternate functions. 296 277 278 + config GPIO_SYSCON 279 + tristate "GPIO based on SYSCON" 280 + depends on MFD_SYSCON && OF 281 + help 282 + Say yes here to support GPIO functionality though SYSCON driver. 283 + 297 284 config GPIO_TS5500 298 285 tristate "TS-5500 DIO blocks and compatibles" 286 + depends on TS5500 || COMPILE_TEST 299 287 help 300 288 This driver supports Digital I/O exposed by pin blocks found on some 301 289 Technologic Systems platforms. It includes, but is not limited to, 3 ··· 488 462 Select this to enable the MC9S08DZ60 GPIO driver 489 463 490 464 config GPIO_PCA953X 491 - tristate "PCA953x, PCA955x, PCA957x, TCA64xx, and MAX7310 I/O ports" 465 + tristate "PCA95[357]x, PCA9698, TCA64xx, and MAX7310 I/O ports" 492 466 depends on I2C 493 467 help 494 468 Say yes here to provide access to several register-oriented ··· 498 472 4 bits: pca9536, pca9537 499 473 500 474 8 bits: max7310, max7315, pca6107, pca9534, pca9538, pca9554, 501 - pca9556, pca9557, pca9574, tca6408 475 + pca9556, pca9557, pca9574, tca6408, xra1202 502 476 503 477 16 bits: max7312, max7313, pca9535, pca9539, pca9555, pca9575, 504 478 tca6416 479 + 480 + 24 bits: tca6424 481 + 482 + 40 bits: pca9505, pca9698 505 483 506 484 config GPIO_PCA953X_IRQ 507 485 bool "Interrupt controller support for PCA953x" ··· 660 630 661 631 config GPIO_CS5535 662 632 tristate "AMD CS5535/CS5536 GPIO support" 663 - depends on PCI && X86 && MFD_CS5535 633 + depends on MFD_CS5535 664 634 help 665 635 The AMD CS5535 and CS5536 southbridges support 28 GPIO pins that 666 636 can be used for quite a number of things. The CS5535/6 is found on ··· 672 642 tristate "BT8XX GPIO abuser" 673 643 depends on PCI && VIDEO_BT848=n 674 644 help 675 - The BT8xx frame grabber chip has 24 GPIO pins than can be abused 645 + The BT8xx frame grabber chip has 24 GPIO pins that can be abused 676 646 as a cheap PCI GPIO card. 677 647 678 648 This chip can be found on Miro, Hauppauge and STB TV-cards.
+3 -1
drivers/gpio/Makefile
··· 23 23 obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o 24 24 obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o 25 25 obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o 26 + obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o 26 27 obj-$(CONFIG_GPIO_EM) += gpio-em.o 27 28 obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 28 29 obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o ··· 77 76 obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o 78 77 obj-$(CONFIG_GPIO_STP_XWAY) += gpio-stp-xway.o 79 78 obj-$(CONFIG_GPIO_SX150X) += gpio-sx150x.o 79 + obj-$(CONFIG_GPIO_SYSCON) += gpio-syscon.o 80 80 obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o 81 81 obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o 82 82 obj-$(CONFIG_ARCH_TEGRA) += gpio-tegra.o 83 83 obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o 84 - obj-$(CONFIG_ARCH_DAVINCI_TNETV107X) += gpio-tnetv107x.o 85 84 obj-$(CONFIG_GPIO_PALMAS) += gpio-palmas.o 86 85 obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o 87 86 obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o ··· 100 99 obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o 101 100 obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o 102 101 obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 102 + obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o
+7 -8
drivers/gpio/gpio-adnp.c
··· 408 408 mutex_unlock(&adnp->irq_lock); 409 409 } 410 410 411 - static unsigned int adnp_irq_startup(struct irq_data *data) 411 + static int adnp_irq_reqres(struct irq_data *data) 412 412 { 413 413 struct adnp *adnp = irq_data_get_irq_chip_data(data); 414 414 415 - if (gpio_lock_as_irq(&adnp->gpio, data->hwirq)) 415 + if (gpio_lock_as_irq(&adnp->gpio, data->hwirq)) { 416 416 dev_err(adnp->gpio.dev, 417 417 "unable to lock HW IRQ %lu for IRQ\n", 418 418 data->hwirq); 419 - /* Satisfy the .enable semantics by unmasking the line */ 420 - adnp_irq_unmask(data); 419 + return -EINVAL; 420 + } 421 421 return 0; 422 422 } 423 423 424 - static void adnp_irq_shutdown(struct irq_data *data) 424 + static void adnp_irq_relres(struct irq_data *data) 425 425 { 426 426 struct adnp *adnp = irq_data_get_irq_chip_data(data); 427 427 428 - adnp_irq_mask(data); 429 428 gpio_unlock_as_irq(&adnp->gpio, data->hwirq); 430 429 } 431 430 ··· 435 436 .irq_set_type = adnp_irq_set_type, 436 437 .irq_bus_lock = adnp_irq_bus_lock, 437 438 .irq_bus_sync_unlock = adnp_irq_bus_unlock, 438 - .irq_startup = adnp_irq_startup, 439 - .irq_shutdown = adnp_irq_shutdown, 439 + .irq_request_resources = adnp_irq_reqres, 440 + .irq_release_resources = adnp_irq_relres, 440 441 }; 441 442 442 443 static int adnp_irq_map(struct irq_domain *domain, unsigned int irq,
+14 -2
drivers/gpio/gpio-adp5588.c
··· 67 67 { 68 68 struct adp5588_gpio *dev = 69 69 container_of(chip, struct adp5588_gpio, gpio_chip); 70 + unsigned bank = ADP5588_BANK(off); 71 + unsigned bit = ADP5588_BIT(off); 72 + int val; 70 73 71 - return !!(adp5588_gpio_read(dev->client, 72 - GPIO_DAT_STAT1 + ADP5588_BANK(off)) & ADP5588_BIT(off)); 74 + mutex_lock(&dev->lock); 75 + 76 + if (dev->dir[bank] & bit) 77 + val = dev->dat_out[bank]; 78 + else 79 + val = adp5588_gpio_read(dev->client, GPIO_DAT_STAT1 + bank); 80 + 81 + mutex_unlock(&dev->lock); 82 + 83 + return !!(val & bit); 73 84 } 74 85 75 86 static void adp5588_gpio_set_value(struct gpio_chip *chip, ··· 397 386 gc->ngpio = ADP5588_MAXGPIO; 398 387 gc->label = client->name; 399 388 gc->owner = THIS_MODULE; 389 + gc->names = pdata->names; 400 390 401 391 mutex_init(&dev->lock); 402 392
+64 -45
drivers/gpio/gpio-bcm-kona.c
··· 28 28 #define GPIO_BANK(gpio) ((gpio) >> 5) 29 29 #define GPIO_BIT(gpio) ((gpio) & (GPIO_PER_BANK - 1)) 30 30 31 + /* There is a GPIO control register for each GPIO */ 32 + #define GPIO_CONTROL(gpio) (0x00000100 + ((gpio) << 2)) 33 + 34 + /* The remaining registers are per GPIO bank */ 31 35 #define GPIO_OUT_STATUS(bank) (0x00000000 + ((bank) << 2)) 32 36 #define GPIO_IN_STATUS(bank) (0x00000020 + ((bank) << 2)) 33 37 #define GPIO_OUT_SET(bank) (0x00000040 + ((bank) << 2)) ··· 39 35 #define GPIO_INT_STATUS(bank) (0x00000080 + ((bank) << 2)) 40 36 #define GPIO_INT_MASK(bank) (0x000000a0 + ((bank) << 2)) 41 37 #define GPIO_INT_MSKCLR(bank) (0x000000c0 + ((bank) << 2)) 42 - #define GPIO_CONTROL(bank) (0x00000100 + ((bank) << 2)) 43 38 #define GPIO_PWD_STATUS(bank) (0x00000500 + ((bank) << 2)) 44 39 45 40 #define GPIO_GPPWR_OFFSET 0x00000520 ··· 83 80 return container_of(chip, struct bcm_kona_gpio, gpio_chip); 84 81 } 85 82 86 - static void bcm_kona_gpio_set_lockcode_bank(void __iomem *reg_base, 87 - int bank_id, int lockcode) 83 + static inline void bcm_kona_gpio_write_lock_regs(void __iomem *reg_base, 84 + int bank_id, u32 lockcode) 88 85 { 89 86 writel(BCM_GPIO_PASSWD, reg_base + GPIO_GPPWR_OFFSET); 90 87 writel(lockcode, reg_base + GPIO_PWD_STATUS(bank_id)); 91 88 } 92 89 93 - static inline void bcm_kona_gpio_lock_bank(void __iomem *reg_base, int bank_id) 90 + static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio, 91 + unsigned gpio) 94 92 { 95 - bcm_kona_gpio_set_lockcode_bank(reg_base, bank_id, LOCK_CODE); 93 + u32 val; 94 + unsigned long flags; 95 + int bank_id = GPIO_BANK(gpio); 96 + 97 + spin_lock_irqsave(&kona_gpio->lock, flags); 98 + 99 + val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id)); 100 + val |= BIT(gpio); 101 + bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val); 102 + 103 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 96 104 } 97 105 98 - static inline void bcm_kona_gpio_unlock_bank(void __iomem *reg_base, 99 - int bank_id) 106 + static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio, 107 + unsigned gpio) 100 108 { 101 - bcm_kona_gpio_set_lockcode_bank(reg_base, bank_id, UNLOCK_CODE); 109 + u32 val; 110 + unsigned long flags; 111 + int bank_id = GPIO_BANK(gpio); 112 + 113 + spin_lock_irqsave(&kona_gpio->lock, flags); 114 + 115 + val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id)); 116 + val &= ~BIT(gpio); 117 + bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val); 118 + 119 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 102 120 } 103 121 104 122 static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) ··· 134 110 kona_gpio = to_kona_gpio(chip); 135 111 reg_base = kona_gpio->reg_base; 136 112 spin_lock_irqsave(&kona_gpio->lock, flags); 137 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 138 113 139 114 /* determine the GPIO pin direction */ 140 115 val = readl(reg_base + GPIO_CONTROL(gpio)); ··· 150 127 writel(val, reg_base + reg_offset); 151 128 152 129 out: 153 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 154 130 spin_unlock_irqrestore(&kona_gpio->lock, flags); 155 131 } 156 132 ··· 165 143 kona_gpio = to_kona_gpio(chip); 166 144 reg_base = kona_gpio->reg_base; 167 145 spin_lock_irqsave(&kona_gpio->lock, flags); 168 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 169 146 170 147 /* determine the GPIO pin direction */ 171 148 val = readl(reg_base + GPIO_CONTROL(gpio)); ··· 175 154 GPIO_IN_STATUS(bank_id) : GPIO_OUT_STATUS(bank_id); 176 155 val = readl(reg_base + reg_offset); 177 156 178 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 179 157 spin_unlock_irqrestore(&kona_gpio->lock, flags); 180 158 181 159 /* return the specified bit status */ 182 160 return !!(val & BIT(bit)); 161 + } 162 + 163 + static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio) 164 + { 165 + struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); 166 + 167 + bcm_kona_gpio_unlock_gpio(kona_gpio, gpio); 168 + return 0; 169 + } 170 + 171 + static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio) 172 + { 173 + struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); 174 + 175 + bcm_kona_gpio_lock_gpio(kona_gpio, gpio); 183 176 } 184 177 185 178 static int bcm_kona_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) ··· 202 167 void __iomem *reg_base; 203 168 u32 val; 204 169 unsigned long flags; 205 - int bank_id = GPIO_BANK(gpio); 206 170 207 171 kona_gpio = to_kona_gpio(chip); 208 172 reg_base = kona_gpio->reg_base; 209 173 spin_lock_irqsave(&kona_gpio->lock, flags); 210 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 211 174 212 175 val = readl(reg_base + GPIO_CONTROL(gpio)); 213 176 val &= ~GPIO_GPCTR0_IOTR_MASK; 214 177 val |= GPIO_GPCTR0_IOTR_CMD_INPUT; 215 178 writel(val, reg_base + GPIO_CONTROL(gpio)); 216 179 217 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 218 180 spin_unlock_irqrestore(&kona_gpio->lock, flags); 219 181 220 182 return 0; ··· 230 198 kona_gpio = to_kona_gpio(chip); 231 199 reg_base = kona_gpio->reg_base; 232 200 spin_lock_irqsave(&kona_gpio->lock, flags); 233 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 234 201 235 202 val = readl(reg_base + GPIO_CONTROL(gpio)); 236 203 val &= ~GPIO_GPCTR0_IOTR_MASK; ··· 241 210 val |= BIT(bit); 242 211 writel(val, reg_base + reg_offset); 243 212 244 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 245 213 spin_unlock_irqrestore(&kona_gpio->lock, flags); 246 214 247 215 return 0; ··· 263 233 void __iomem *reg_base; 264 234 u32 val, res; 265 235 unsigned long flags; 266 - int bank_id = GPIO_BANK(gpio); 267 236 268 237 kona_gpio = to_kona_gpio(chip); 269 238 reg_base = kona_gpio->reg_base; ··· 286 257 287 258 /* spin lock for read-modify-write of the GPIO register */ 288 259 spin_lock_irqsave(&kona_gpio->lock, flags); 289 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 290 260 291 261 val = readl(reg_base + GPIO_CONTROL(gpio)); 292 262 val &= ~GPIO_GPCTR0_DBR_MASK; ··· 300 272 301 273 writel(val, reg_base + GPIO_CONTROL(gpio)); 302 274 303 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 304 275 spin_unlock_irqrestore(&kona_gpio->lock, flags); 305 276 306 277 return 0; ··· 308 281 static struct gpio_chip template_chip = { 309 282 .label = "bcm-kona-gpio", 310 283 .owner = THIS_MODULE, 284 + .request = bcm_kona_gpio_request, 285 + .free = bcm_kona_gpio_free, 311 286 .direction_input = bcm_kona_gpio_direction_input, 312 287 .get = bcm_kona_gpio_get, 313 288 .direction_output = bcm_kona_gpio_direction_output, ··· 323 294 { 324 295 struct bcm_kona_gpio *kona_gpio; 325 296 void __iomem *reg_base; 326 - int gpio = d->hwirq; 297 + unsigned gpio = d->hwirq; 327 298 int bank_id = GPIO_BANK(gpio); 328 299 int bit = GPIO_BIT(gpio); 329 300 u32 val; ··· 332 303 kona_gpio = irq_data_get_irq_chip_data(d); 333 304 reg_base = kona_gpio->reg_base; 334 305 spin_lock_irqsave(&kona_gpio->lock, flags); 335 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 336 306 337 307 val = readl(reg_base + GPIO_INT_STATUS(bank_id)); 338 308 val |= BIT(bit); 339 309 writel(val, reg_base + GPIO_INT_STATUS(bank_id)); 340 310 341 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 342 311 spin_unlock_irqrestore(&kona_gpio->lock, flags); 343 312 } 344 313 ··· 344 317 { 345 318 struct bcm_kona_gpio *kona_gpio; 346 319 void __iomem *reg_base; 347 - int gpio = d->hwirq; 320 + unsigned gpio = d->hwirq; 348 321 int bank_id = GPIO_BANK(gpio); 349 322 int bit = GPIO_BIT(gpio); 350 323 u32 val; ··· 353 326 kona_gpio = irq_data_get_irq_chip_data(d); 354 327 reg_base = kona_gpio->reg_base; 355 328 spin_lock_irqsave(&kona_gpio->lock, flags); 356 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 357 329 358 330 val = readl(reg_base + GPIO_INT_MASK(bank_id)); 359 331 val |= BIT(bit); 360 332 writel(val, reg_base + GPIO_INT_MASK(bank_id)); 361 333 362 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 363 334 spin_unlock_irqrestore(&kona_gpio->lock, flags); 364 335 } 365 336 ··· 365 340 { 366 341 struct bcm_kona_gpio *kona_gpio; 367 342 void __iomem *reg_base; 368 - int gpio = d->hwirq; 343 + unsigned gpio = d->hwirq; 369 344 int bank_id = GPIO_BANK(gpio); 370 345 int bit = GPIO_BIT(gpio); 371 346 u32 val; ··· 374 349 kona_gpio = irq_data_get_irq_chip_data(d); 375 350 reg_base = kona_gpio->reg_base; 376 351 spin_lock_irqsave(&kona_gpio->lock, flags); 377 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 378 352 379 353 val = readl(reg_base + GPIO_INT_MSKCLR(bank_id)); 380 354 val |= BIT(bit); 381 355 writel(val, reg_base + GPIO_INT_MSKCLR(bank_id)); 382 356 383 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 384 357 spin_unlock_irqrestore(&kona_gpio->lock, flags); 385 358 } 386 359 ··· 386 363 { 387 364 struct bcm_kona_gpio *kona_gpio; 388 365 void __iomem *reg_base; 389 - int gpio = d->hwirq; 366 + unsigned gpio = d->hwirq; 390 367 u32 lvl_type; 391 368 u32 val; 392 369 unsigned long flags; 393 - int bank_id = GPIO_BANK(gpio); 394 370 395 371 kona_gpio = irq_data_get_irq_chip_data(d); 396 372 reg_base = kona_gpio->reg_base; ··· 416 394 } 417 395 418 396 spin_lock_irqsave(&kona_gpio->lock, flags); 419 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 420 397 421 398 val = readl(reg_base + GPIO_CONTROL(gpio)); 422 399 val &= ~GPIO_GPCTR0_ITR_MASK; 423 400 val |= lvl_type << GPIO_GPCTR0_ITR_SHIFT; 424 401 writel(val, reg_base + GPIO_CONTROL(gpio)); 425 402 426 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 427 403 spin_unlock_irqrestore(&kona_gpio->lock, flags); 428 404 429 405 return 0; ··· 444 424 */ 445 425 reg_base = bank->kona_gpio->reg_base; 446 426 bank_id = bank->id; 447 - bcm_kona_gpio_unlock_bank(reg_base, bank_id); 448 427 449 428 while ((sta = readl(reg_base + GPIO_INT_STATUS(bank_id)) & 450 429 (~(readl(reg_base + GPIO_INT_MASK(bank_id)))))) { ··· 463 444 } 464 445 } 465 446 466 - bcm_kona_gpio_lock_bank(reg_base, bank_id); 467 - 468 447 chained_irq_exit(chip, desc); 469 448 } 470 449 471 - static unsigned int bcm_kona_gpio_irq_startup(struct irq_data *d) 450 + static int bcm_kona_gpio_irq_reqres(struct irq_data *d) 472 451 { 473 452 struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); 474 453 475 - if (gpio_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) 454 + if (gpio_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) { 476 455 dev_err(kona_gpio->gpio_chip.dev, 477 456 "unable to lock HW IRQ %lu for IRQ\n", 478 457 d->hwirq); 479 - bcm_kona_gpio_irq_unmask(d); 458 + return -EINVAL; 459 + } 480 460 return 0; 481 461 } 482 462 483 - static void bcm_kona_gpio_irq_shutdown(struct irq_data *d) 463 + static void bcm_kona_gpio_irq_relres(struct irq_data *d) 484 464 { 485 465 struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); 486 466 487 - bcm_kona_gpio_irq_mask(d); 488 467 gpio_unlock_as_irq(&kona_gpio->gpio_chip, d->hwirq); 489 468 } 490 469 ··· 492 475 .irq_mask = bcm_kona_gpio_irq_mask, 493 476 .irq_unmask = bcm_kona_gpio_irq_unmask, 494 477 .irq_set_type = bcm_kona_gpio_irq_set_type, 495 - .irq_startup = bcm_kona_gpio_irq_startup, 496 - .irq_shutdown = bcm_kona_gpio_irq_shutdown, 478 + .irq_request_resources = bcm_kona_gpio_irq_reqres, 479 + .irq_release_resources = bcm_kona_gpio_irq_relres, 497 480 }; 498 481 499 482 static struct __initconst of_device_id bcm_kona_gpio_of_match[] = { ··· 548 531 reg_base = kona_gpio->reg_base; 549 532 /* disable interrupts and clear status */ 550 533 for (i = 0; i < kona_gpio->num_bank; i++) { 551 - bcm_kona_gpio_unlock_bank(reg_base, i); 534 + /* Unlock the entire bank first */ 535 + bcm_kona_gpio_write_lock_regs(kona_gpio, i, UNLOCK_CODE); 552 536 writel(0xffffffff, reg_base + GPIO_INT_MASK(i)); 553 537 writel(0xffffffff, reg_base + GPIO_INT_STATUS(i)); 554 - bcm_kona_gpio_lock_bank(reg_base, i); 538 + /* Now re-lock the bank */ 539 + bcm_kona_gpio_write_lock_regs(kona_gpio, i, LOCK_CODE); 555 540 } 556 541 } 557 542
+1
drivers/gpio/gpio-clps711x.c
··· 65 65 } 66 66 67 67 bgc->gc.base = id * 8; 68 + bgc->gc.owner = THIS_MODULE; 68 69 platform_set_drvdata(pdev, bgc); 69 70 70 71 return gpiochip_add(&bgc->gc);
+66 -9
drivers/gpio/gpio-davinci.c
··· 37 37 u32 intstat; 38 38 }; 39 39 40 + typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq); 41 + 40 42 #define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */ 41 43 42 44 #define chip2controller(chip) \ ··· 174 172 return NULL; 175 173 } 176 174 175 + #ifdef CONFIG_OF_GPIO 176 + static int davinci_gpio_of_xlate(struct gpio_chip *gc, 177 + const struct of_phandle_args *gpiospec, 178 + u32 *flags) 179 + { 180 + struct davinci_gpio_controller *chips = dev_get_drvdata(gc->dev); 181 + struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->dev); 182 + 183 + if (gpiospec->args[0] > pdata->ngpio) 184 + return -EINVAL; 185 + 186 + if (gc != &chips[gpiospec->args[0] / 32].chip) 187 + return -EINVAL; 188 + 189 + if (flags) 190 + *flags = gpiospec->args[1]; 191 + 192 + return gpiospec->args[0] % 32; 193 + } 194 + #endif 195 + 177 196 static int davinci_gpio_probe(struct platform_device *pdev) 178 197 { 179 198 int i, base; ··· 259 236 chips[i].chip.ngpio = 32; 260 237 261 238 #ifdef CONFIG_OF_GPIO 239 + chips[i].chip.of_gpio_n_cells = 2; 240 + chips[i].chip.of_xlate = davinci_gpio_of_xlate; 241 + chips[i].chip.dev = dev; 262 242 chips[i].chip.of_node = dev->of_node; 263 243 #endif 264 244 spin_lock_init(&chips[i].lock); ··· 439 413 .xlate = irq_domain_xlate_onetwocell, 440 414 }; 441 415 416 + static struct irq_chip *davinci_gpio_get_irq_chip(unsigned int irq) 417 + { 418 + static struct irq_chip_type gpio_unbanked; 419 + 420 + gpio_unbanked = *container_of(irq_get_chip(irq), 421 + struct irq_chip_type, chip); 422 + 423 + return &gpio_unbanked.chip; 424 + }; 425 + 426 + static struct irq_chip *keystone_gpio_get_irq_chip(unsigned int irq) 427 + { 428 + static struct irq_chip gpio_unbanked; 429 + 430 + gpio_unbanked = *irq_get_chip(irq); 431 + return &gpio_unbanked; 432 + }; 433 + 434 + static const struct of_device_id davinci_gpio_ids[]; 435 + 442 436 /* 443 437 * NOTE: for suspend/resume, probably best to make a platform_device with 444 438 * suspend_late/resume_resume calls hooking into results of the set_wake() ··· 469 423 470 424 static int davinci_gpio_irq_setup(struct platform_device *pdev) 471 425 { 472 - unsigned gpio, irq, bank; 426 + unsigned gpio, bank; 427 + int irq; 473 428 struct clk *clk; 474 429 u32 binten = 0; 475 430 unsigned ngpio, bank_irq; ··· 480 433 struct davinci_gpio_platform_data *pdata = dev->platform_data; 481 434 struct davinci_gpio_regs __iomem *g; 482 435 struct irq_domain *irq_domain = NULL; 436 + const struct of_device_id *match; 437 + struct irq_chip *irq_chip; 438 + gpio_get_irq_chip_cb_t gpio_get_irq_chip; 439 + 440 + /* 441 + * Use davinci_gpio_get_irq_chip by default to handle non DT cases 442 + */ 443 + gpio_get_irq_chip = davinci_gpio_get_irq_chip; 444 + match = of_match_device(of_match_ptr(davinci_gpio_ids), 445 + dev); 446 + if (match) 447 + gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)match->data; 483 448 484 449 ngpio = pdata->ngpio; 485 450 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); ··· 548 489 * IRQ mux conflicts; gpio_irq_type_unbanked() is only for GPIOs. 549 490 */ 550 491 if (pdata->gpio_unbanked) { 551 - static struct irq_chip_type gpio_unbanked; 552 - 553 492 /* pass "bank 0" GPIO IRQs to AINTC */ 554 493 chips[0].chip.to_irq = gpio_to_irq_unbanked; 555 494 chips[0].gpio_irq = bank_irq; ··· 556 499 557 500 /* AINTC handles mask/unmask; GPIO handles triggering */ 558 501 irq = bank_irq; 559 - gpio_unbanked = *container_of(irq_get_chip(irq), 560 - struct irq_chip_type, chip); 561 - gpio_unbanked.chip.name = "GPIO-AINTC"; 562 - gpio_unbanked.chip.irq_set_type = gpio_irq_type_unbanked; 502 + irq_chip = gpio_get_irq_chip(irq); 503 + irq_chip->name = "GPIO-AINTC"; 504 + irq_chip->irq_set_type = gpio_irq_type_unbanked; 563 505 564 506 /* default trigger: both edges */ 565 507 g = gpio2regs(0); ··· 567 511 568 512 /* set the direct IRQs up to use that irqchip */ 569 513 for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) { 570 - irq_set_chip(irq, &gpio_unbanked.chip); 514 + irq_set_chip(irq, irq_chip); 571 515 irq_set_handler_data(irq, &chips[gpio / 32]); 572 516 irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); 573 517 } ··· 610 554 611 555 #if IS_ENABLED(CONFIG_OF) 612 556 static const struct of_device_id davinci_gpio_ids[] = { 613 - { .compatible = "ti,dm6441-gpio", }, 557 + { .compatible = "ti,keystone-gpio", keystone_gpio_get_irq_chip}, 558 + { .compatible = "ti,dm6441-gpio", davinci_gpio_get_irq_chip}, 614 559 { /* sentinel */ }, 615 560 }; 616 561 MODULE_DEVICE_TABLE(of, davinci_gpio_ids);
+438
drivers/gpio/gpio-dwapb.c
··· 1 + /* 2 + * Copyright (c) 2011 Jamie Iles 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 + * All enquiries to support@picochip.com 9 + */ 10 + #include <linux/basic_mmio_gpio.h> 11 + #include <linux/err.h> 12 + #include <linux/init.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/io.h> 15 + #include <linux/ioport.h> 16 + #include <linux/irq.h> 17 + #include <linux/irqdomain.h> 18 + #include <linux/module.h> 19 + #include <linux/of.h> 20 + #include <linux/of_address.h> 21 + #include <linux/of_irq.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/spinlock.h> 24 + 25 + #define GPIO_SWPORTA_DR 0x00 26 + #define GPIO_SWPORTA_DDR 0x04 27 + #define GPIO_SWPORTB_DR 0x0c 28 + #define GPIO_SWPORTB_DDR 0x10 29 + #define GPIO_SWPORTC_DR 0x18 30 + #define GPIO_SWPORTC_DDR 0x1c 31 + #define GPIO_SWPORTD_DR 0x24 32 + #define GPIO_SWPORTD_DDR 0x28 33 + #define GPIO_INTEN 0x30 34 + #define GPIO_INTMASK 0x34 35 + #define GPIO_INTTYPE_LEVEL 0x38 36 + #define GPIO_INT_POLARITY 0x3c 37 + #define GPIO_INTSTATUS 0x40 38 + #define GPIO_PORTA_EOI 0x4c 39 + #define GPIO_EXT_PORTA 0x50 40 + #define GPIO_EXT_PORTB 0x54 41 + #define GPIO_EXT_PORTC 0x58 42 + #define GPIO_EXT_PORTD 0x5c 43 + 44 + #define DWAPB_MAX_PORTS 4 45 + #define GPIO_EXT_PORT_SIZE (GPIO_EXT_PORTB - GPIO_EXT_PORTA) 46 + #define GPIO_SWPORT_DR_SIZE (GPIO_SWPORTB_DR - GPIO_SWPORTA_DR) 47 + #define GPIO_SWPORT_DDR_SIZE (GPIO_SWPORTB_DDR - GPIO_SWPORTA_DDR) 48 + 49 + struct dwapb_gpio; 50 + 51 + struct dwapb_gpio_port { 52 + struct bgpio_chip bgc; 53 + bool is_registered; 54 + struct dwapb_gpio *gpio; 55 + }; 56 + 57 + struct dwapb_gpio { 58 + struct device *dev; 59 + void __iomem *regs; 60 + struct dwapb_gpio_port *ports; 61 + unsigned int nr_ports; 62 + struct irq_domain *domain; 63 + }; 64 + 65 + static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 66 + { 67 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 68 + struct dwapb_gpio_port *port = container_of(bgc, struct 69 + dwapb_gpio_port, bgc); 70 + struct dwapb_gpio *gpio = port->gpio; 71 + 72 + return irq_find_mapping(gpio->domain, offset); 73 + } 74 + 75 + static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs) 76 + { 77 + u32 v = readl(gpio->regs + GPIO_INT_POLARITY); 78 + 79 + if (gpio_get_value(gpio->ports[0].bgc.gc.base + offs)) 80 + v &= ~BIT(offs); 81 + else 82 + v |= BIT(offs); 83 + 84 + writel(v, gpio->regs + GPIO_INT_POLARITY); 85 + } 86 + 87 + static void dwapb_irq_handler(u32 irq, struct irq_desc *desc) 88 + { 89 + struct dwapb_gpio *gpio = irq_get_handler_data(irq); 90 + struct irq_chip *chip = irq_desc_get_chip(desc); 91 + u32 irq_status = readl_relaxed(gpio->regs + GPIO_INTSTATUS); 92 + 93 + while (irq_status) { 94 + int hwirq = fls(irq_status) - 1; 95 + int gpio_irq = irq_find_mapping(gpio->domain, hwirq); 96 + 97 + generic_handle_irq(gpio_irq); 98 + irq_status &= ~BIT(hwirq); 99 + 100 + if ((irq_get_trigger_type(gpio_irq) & IRQ_TYPE_SENSE_MASK) 101 + == IRQ_TYPE_EDGE_BOTH) 102 + dwapb_toggle_trigger(gpio, hwirq); 103 + } 104 + 105 + if (chip->irq_eoi) 106 + chip->irq_eoi(irq_desc_get_irq_data(desc)); 107 + } 108 + 109 + static void dwapb_irq_enable(struct irq_data *d) 110 + { 111 + struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 112 + struct dwapb_gpio *gpio = igc->private; 113 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 114 + unsigned long flags; 115 + u32 val; 116 + 117 + spin_lock_irqsave(&bgc->lock, flags); 118 + val = readl(gpio->regs + GPIO_INTEN); 119 + val |= BIT(d->hwirq); 120 + writel(val, gpio->regs + GPIO_INTEN); 121 + spin_unlock_irqrestore(&bgc->lock, flags); 122 + } 123 + 124 + static void dwapb_irq_disable(struct irq_data *d) 125 + { 126 + struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 127 + struct dwapb_gpio *gpio = igc->private; 128 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 129 + unsigned long flags; 130 + u32 val; 131 + 132 + spin_lock_irqsave(&bgc->lock, flags); 133 + val = readl(gpio->regs + GPIO_INTEN); 134 + val &= ~BIT(d->hwirq); 135 + writel(val, gpio->regs + GPIO_INTEN); 136 + spin_unlock_irqrestore(&bgc->lock, flags); 137 + } 138 + 139 + static int dwapb_irq_reqres(struct irq_data *d) 140 + { 141 + struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 142 + struct dwapb_gpio *gpio = igc->private; 143 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 144 + 145 + if (gpio_lock_as_irq(&bgc->gc, irqd_to_hwirq(d))) { 146 + dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", 147 + irqd_to_hwirq(d)); 148 + return -EINVAL; 149 + } 150 + return 0; 151 + } 152 + 153 + static void dwapb_irq_relres(struct irq_data *d) 154 + { 155 + struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 156 + struct dwapb_gpio *gpio = igc->private; 157 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 158 + 159 + gpio_unlock_as_irq(&bgc->gc, irqd_to_hwirq(d)); 160 + } 161 + 162 + static int dwapb_irq_set_type(struct irq_data *d, u32 type) 163 + { 164 + struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 165 + struct dwapb_gpio *gpio = igc->private; 166 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 167 + int bit = d->hwirq; 168 + unsigned long level, polarity, flags; 169 + 170 + if (type & ~(IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | 171 + IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 172 + return -EINVAL; 173 + 174 + spin_lock_irqsave(&bgc->lock, flags); 175 + level = readl(gpio->regs + GPIO_INTTYPE_LEVEL); 176 + polarity = readl(gpio->regs + GPIO_INT_POLARITY); 177 + 178 + switch (type) { 179 + case IRQ_TYPE_EDGE_BOTH: 180 + level |= BIT(bit); 181 + dwapb_toggle_trigger(gpio, bit); 182 + break; 183 + case IRQ_TYPE_EDGE_RISING: 184 + level |= BIT(bit); 185 + polarity |= BIT(bit); 186 + break; 187 + case IRQ_TYPE_EDGE_FALLING: 188 + level |= BIT(bit); 189 + polarity &= ~BIT(bit); 190 + break; 191 + case IRQ_TYPE_LEVEL_HIGH: 192 + level &= ~BIT(bit); 193 + polarity |= BIT(bit); 194 + break; 195 + case IRQ_TYPE_LEVEL_LOW: 196 + level &= ~BIT(bit); 197 + polarity &= ~BIT(bit); 198 + break; 199 + } 200 + 201 + writel(level, gpio->regs + GPIO_INTTYPE_LEVEL); 202 + writel(polarity, gpio->regs + GPIO_INT_POLARITY); 203 + spin_unlock_irqrestore(&bgc->lock, flags); 204 + 205 + return 0; 206 + } 207 + 208 + static void dwapb_configure_irqs(struct dwapb_gpio *gpio, 209 + struct dwapb_gpio_port *port) 210 + { 211 + struct gpio_chip *gc = &port->bgc.gc; 212 + struct device_node *node = gc->of_node; 213 + struct irq_chip_generic *irq_gc; 214 + unsigned int hwirq, ngpio = gc->ngpio; 215 + struct irq_chip_type *ct; 216 + int err, irq; 217 + 218 + irq = irq_of_parse_and_map(node, 0); 219 + if (!irq) { 220 + dev_warn(gpio->dev, "no irq for bank %s\n", 221 + port->bgc.gc.of_node->full_name); 222 + return; 223 + } 224 + 225 + gpio->domain = irq_domain_add_linear(node, ngpio, 226 + &irq_generic_chip_ops, gpio); 227 + if (!gpio->domain) 228 + return; 229 + 230 + err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 1, 231 + "gpio-dwapb", handle_level_irq, 232 + IRQ_NOREQUEST, 0, 233 + IRQ_GC_INIT_NESTED_LOCK); 234 + if (err) { 235 + dev_info(gpio->dev, "irq_alloc_domain_generic_chips failed\n"); 236 + irq_domain_remove(gpio->domain); 237 + gpio->domain = NULL; 238 + return; 239 + } 240 + 241 + irq_gc = irq_get_domain_generic_chip(gpio->domain, 0); 242 + if (!irq_gc) { 243 + irq_domain_remove(gpio->domain); 244 + gpio->domain = NULL; 245 + return; 246 + } 247 + 248 + irq_gc->reg_base = gpio->regs; 249 + irq_gc->private = gpio; 250 + 251 + ct = irq_gc->chip_types; 252 + ct->chip.irq_ack = irq_gc_ack_set_bit; 253 + ct->chip.irq_mask = irq_gc_mask_set_bit; 254 + ct->chip.irq_unmask = irq_gc_mask_clr_bit; 255 + ct->chip.irq_set_type = dwapb_irq_set_type; 256 + ct->chip.irq_enable = dwapb_irq_enable; 257 + ct->chip.irq_disable = dwapb_irq_disable; 258 + ct->chip.irq_request_resources = dwapb_irq_reqres; 259 + ct->chip.irq_release_resources = dwapb_irq_relres; 260 + ct->regs.ack = GPIO_PORTA_EOI; 261 + ct->regs.mask = GPIO_INTMASK; 262 + 263 + irq_setup_generic_chip(irq_gc, IRQ_MSK(port->bgc.gc.ngpio), 264 + IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); 265 + 266 + irq_set_chained_handler(irq, dwapb_irq_handler); 267 + irq_set_handler_data(irq, gpio); 268 + 269 + for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 270 + irq_create_mapping(gpio->domain, hwirq); 271 + 272 + port->bgc.gc.to_irq = dwapb_gpio_to_irq; 273 + } 274 + 275 + static void dwapb_irq_teardown(struct dwapb_gpio *gpio) 276 + { 277 + struct dwapb_gpio_port *port = &gpio->ports[0]; 278 + struct gpio_chip *gc = &port->bgc.gc; 279 + unsigned int ngpio = gc->ngpio; 280 + irq_hw_number_t hwirq; 281 + 282 + if (!gpio->domain) 283 + return; 284 + 285 + for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 286 + irq_dispose_mapping(irq_find_mapping(gpio->domain, hwirq)); 287 + 288 + irq_domain_remove(gpio->domain); 289 + gpio->domain = NULL; 290 + } 291 + 292 + static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, 293 + struct device_node *port_np, 294 + unsigned int offs) 295 + { 296 + struct dwapb_gpio_port *port; 297 + u32 port_idx, ngpio; 298 + void __iomem *dat, *set, *dirout; 299 + int err; 300 + 301 + if (of_property_read_u32(port_np, "reg", &port_idx) || 302 + port_idx >= DWAPB_MAX_PORTS) { 303 + dev_err(gpio->dev, "missing/invalid port index for %s\n", 304 + port_np->full_name); 305 + return -EINVAL; 306 + } 307 + 308 + port = &gpio->ports[offs]; 309 + port->gpio = gpio; 310 + 311 + if (of_property_read_u32(port_np, "snps,nr-gpios", &ngpio)) { 312 + dev_info(gpio->dev, "failed to get number of gpios for %s\n", 313 + port_np->full_name); 314 + ngpio = 32; 315 + } 316 + 317 + dat = gpio->regs + GPIO_EXT_PORTA + (port_idx * GPIO_EXT_PORT_SIZE); 318 + set = gpio->regs + GPIO_SWPORTA_DR + (port_idx * GPIO_SWPORT_DR_SIZE); 319 + dirout = gpio->regs + GPIO_SWPORTA_DDR + 320 + (port_idx * GPIO_SWPORT_DDR_SIZE); 321 + 322 + err = bgpio_init(&port->bgc, gpio->dev, 4, dat, set, NULL, dirout, 323 + NULL, false); 324 + if (err) { 325 + dev_err(gpio->dev, "failed to init gpio chip for %s\n", 326 + port_np->full_name); 327 + return err; 328 + } 329 + 330 + port->bgc.gc.ngpio = ngpio; 331 + port->bgc.gc.of_node = port_np; 332 + 333 + /* 334 + * Only port A can provide interrupts in all configurations of the IP. 335 + */ 336 + if (port_idx == 0 && 337 + of_property_read_bool(port_np, "interrupt-controller")) 338 + dwapb_configure_irqs(gpio, port); 339 + 340 + err = gpiochip_add(&port->bgc.gc); 341 + if (err) 342 + dev_err(gpio->dev, "failed to register gpiochip for %s\n", 343 + port_np->full_name); 344 + else 345 + port->is_registered = true; 346 + 347 + return err; 348 + } 349 + 350 + static void dwapb_gpio_unregister(struct dwapb_gpio *gpio) 351 + { 352 + unsigned int m; 353 + 354 + for (m = 0; m < gpio->nr_ports; ++m) 355 + if (gpio->ports[m].is_registered) 356 + WARN_ON(gpiochip_remove(&gpio->ports[m].bgc.gc)); 357 + } 358 + 359 + static int dwapb_gpio_probe(struct platform_device *pdev) 360 + { 361 + struct resource *res; 362 + struct dwapb_gpio *gpio; 363 + struct device_node *np; 364 + int err; 365 + unsigned int offs = 0; 366 + 367 + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 368 + if (!gpio) 369 + return -ENOMEM; 370 + gpio->dev = &pdev->dev; 371 + 372 + gpio->nr_ports = of_get_child_count(pdev->dev.of_node); 373 + if (!gpio->nr_ports) { 374 + err = -EINVAL; 375 + goto out_err; 376 + } 377 + gpio->ports = devm_kzalloc(&pdev->dev, gpio->nr_ports * 378 + sizeof(*gpio->ports), GFP_KERNEL); 379 + if (!gpio->ports) { 380 + err = -ENOMEM; 381 + goto out_err; 382 + } 383 + 384 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 385 + gpio->regs = devm_ioremap_resource(&pdev->dev, res); 386 + if (IS_ERR(gpio->regs)) { 387 + err = PTR_ERR(gpio->regs); 388 + goto out_err; 389 + } 390 + 391 + for_each_child_of_node(pdev->dev.of_node, np) { 392 + err = dwapb_gpio_add_port(gpio, np, offs++); 393 + if (err) 394 + goto out_unregister; 395 + } 396 + platform_set_drvdata(pdev, gpio); 397 + 398 + return 0; 399 + 400 + out_unregister: 401 + dwapb_gpio_unregister(gpio); 402 + dwapb_irq_teardown(gpio); 403 + 404 + out_err: 405 + return err; 406 + } 407 + 408 + static int dwapb_gpio_remove(struct platform_device *pdev) 409 + { 410 + struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 411 + 412 + dwapb_gpio_unregister(gpio); 413 + dwapb_irq_teardown(gpio); 414 + 415 + return 0; 416 + } 417 + 418 + static const struct of_device_id dwapb_of_match[] = { 419 + { .compatible = "snps,dw-apb-gpio" }, 420 + { /* Sentinel */ } 421 + }; 422 + MODULE_DEVICE_TABLE(of, dwapb_of_match); 423 + 424 + static struct platform_driver dwapb_gpio_driver = { 425 + .driver = { 426 + .name = "gpio-dwapb", 427 + .owner = THIS_MODULE, 428 + .of_match_table = of_match_ptr(dwapb_of_match), 429 + }, 430 + .probe = dwapb_gpio_probe, 431 + .remove = dwapb_gpio_remove, 432 + }; 433 + 434 + module_platform_driver(dwapb_gpio_driver); 435 + 436 + MODULE_LICENSE("GPL"); 437 + MODULE_AUTHOR("Jamie Iles"); 438 + MODULE_DESCRIPTION("Synopsys DesignWare APB GPIO driver");
+7 -7
drivers/gpio/gpio-em.c
··· 99 99 em_gio_write(p, GIO_IEN, BIT(irqd_to_hwirq(d))); 100 100 } 101 101 102 - static unsigned int em_gio_irq_startup(struct irq_data *d) 102 + static int em_gio_irq_reqres(struct irq_data *d) 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 (gpio_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)); 110 - em_gio_irq_enable(d); 110 + return -EINVAL; 111 + } 111 112 return 0; 112 113 } 113 114 114 - static void em_gio_irq_shutdown(struct irq_data *d) 115 + static void em_gio_irq_relres(struct irq_data *d) 115 116 { 116 117 struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 117 118 118 - em_gio_irq_disable(d); 119 119 gpio_unlock_as_irq(&p->gpio_chip, irqd_to_hwirq(d)); 120 120 } 121 121 ··· 359 359 irq_chip->irq_mask = em_gio_irq_disable; 360 360 irq_chip->irq_unmask = em_gio_irq_enable; 361 361 irq_chip->irq_set_type = em_gio_irq_set_type; 362 - irq_chip->irq_startup = em_gio_irq_startup; 363 - irq_chip->irq_shutdown = em_gio_irq_shutdown; 362 + irq_chip->irq_request_resources = em_gio_irq_reqres; 363 + irq_chip->irq_release_resources = em_gio_irq_relres; 364 364 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND; 365 365 366 366 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node,
+12 -8
drivers/gpio/gpio-generic.c
··· 139 139 { 140 140 struct bgpio_chip *bgc = to_bgpio_chip(gc); 141 141 142 - return bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio); 142 + return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); 143 143 } 144 144 145 145 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) ··· 488 488 void __iomem *dirout; 489 489 void __iomem *dirin; 490 490 unsigned long sz; 491 - unsigned long flags = 0; 491 + unsigned long flags = pdev->id_entry->driver_data; 492 492 int err; 493 493 struct bgpio_chip *bgc; 494 494 struct bgpio_pdata *pdata = dev_get_platdata(dev); ··· 519 519 if (err) 520 520 return err; 521 521 522 - if (!strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be")) 523 - flags |= BGPIOF_BIG_ENDIAN; 524 - 525 522 bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 526 523 if (!bgc) 527 524 return -ENOMEM; ··· 528 531 return err; 529 532 530 533 if (pdata) { 534 + if (pdata->label) 535 + bgc->gc.label = pdata->label; 531 536 bgc->gc.base = pdata->base; 532 537 if (pdata->ngpio > 0) 533 538 bgc->gc.ngpio = pdata->ngpio; ··· 548 549 } 549 550 550 551 static const struct platform_device_id bgpio_id_table[] = { 551 - { "basic-mmio-gpio", }, 552 - { "basic-mmio-gpio-be", }, 553 - {}, 552 + { 553 + .name = "basic-mmio-gpio", 554 + .driver_data = 0, 555 + }, { 556 + .name = "basic-mmio-gpio-be", 557 + .driver_data = BGPIOF_BIG_ENDIAN, 558 + }, 559 + { } 554 560 }; 555 561 MODULE_DEVICE_TABLE(platform, bgpio_id_table); 556 562
+57 -13
drivers/gpio/gpio-ich.c
··· 62 62 /* Max GPIO pins the chipset can have */ 63 63 uint ngpio; 64 64 65 + /* chipset registers */ 66 + const u8 (*regs)[3]; 67 + const u8 *reglen; 68 + 69 + /* GPO_BLINK is available on this chipset */ 70 + bool have_blink; 71 + 65 72 /* Whether the chipset has GPIO in GPE0_STS in the PM IO region */ 66 73 bool uses_gpe0; 67 74 ··· 78 71 /* Some chipsets have quirks, let these use their own request/get */ 79 72 int (*request)(struct gpio_chip *chip, unsigned offset); 80 73 int (*get)(struct gpio_chip *chip, unsigned offset); 74 + 75 + /* 76 + * Some chipsets don't let reading output values on GPIO_LVL register 77 + * this option allows driver caching written output values 78 + */ 79 + bool use_outlvl_cache; 81 80 }; 82 81 83 82 static struct { ··· 95 82 struct ichx_desc *desc; /* Pointer to chipset-specific description */ 96 83 u32 orig_gpio_ctrl; /* Orig CTRL value, used to restore on exit */ 97 84 u8 use_gpio; /* Which GPIO groups are usable */ 85 + int outlvl_cache[3]; /* cached output values */ 98 86 } ichx_priv; 99 87 100 88 static int modparam_gpiobase = -1; /* dynamic */ ··· 113 99 114 100 spin_lock_irqsave(&ichx_priv.lock, flags); 115 101 116 - data = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); 102 + if (reg == GPIO_LVL && ichx_priv.desc->use_outlvl_cache) 103 + data = ichx_priv.outlvl_cache[reg_nr]; 104 + else 105 + data = ICHX_READ(ichx_priv.desc->regs[reg][reg_nr], 106 + ichx_priv.gpio_base); 107 + 117 108 if (val) 118 109 data |= 1 << bit; 119 110 else 120 111 data &= ~(1 << bit); 121 - ICHX_WRITE(data, ichx_regs[reg][reg_nr], ichx_priv.gpio_base); 122 - tmp = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); 112 + ICHX_WRITE(data, ichx_priv.desc->regs[reg][reg_nr], 113 + ichx_priv.gpio_base); 114 + if (reg == GPIO_LVL && ichx_priv.desc->use_outlvl_cache) 115 + ichx_priv.outlvl_cache[reg_nr] = data; 116 + 117 + tmp = ICHX_READ(ichx_priv.desc->regs[reg][reg_nr], 118 + ichx_priv.gpio_base); 123 119 if (verify && data != tmp) 124 120 ret = -EPERM; 125 121 ··· 147 123 148 124 spin_lock_irqsave(&ichx_priv.lock, flags); 149 125 150 - data = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); 126 + data = ICHX_READ(ichx_priv.desc->regs[reg][reg_nr], 127 + ichx_priv.gpio_base); 128 + 129 + if (reg == GPIO_LVL && ichx_priv.desc->use_outlvl_cache) 130 + data = ichx_priv.outlvl_cache[reg_nr] | data; 151 131 152 132 spin_unlock_irqrestore(&ichx_priv.lock, flags); 153 133 ··· 179 151 int val) 180 152 { 181 153 /* Disable blink hardware which is available for GPIOs from 0 to 31. */ 182 - if (nr < 32) 154 + if (nr < 32 && ichx_priv.desc->have_blink) 183 155 ichx_write_bit(GPO_BLINK, nr, 0, 0); 184 156 185 157 /* Set GPIO output value. */ ··· 294 266 .uses_gpe0 = true, 295 267 296 268 .ngpio = 50, 269 + .have_blink = true, 297 270 }; 298 271 299 272 /* Intel 3100 */ ··· 319 290 /* ICH7 and ICH8-based */ 320 291 static struct ichx_desc ich7_desc = { 321 292 .ngpio = 50, 293 + .have_blink = true, 294 + .regs = ichx_regs, 295 + .reglen = ichx_reglen, 322 296 }; 323 297 324 298 /* ICH9-based */ 325 299 static struct ichx_desc ich9_desc = { 326 300 .ngpio = 61, 301 + .have_blink = true, 302 + .regs = ichx_regs, 303 + .reglen = ichx_reglen, 327 304 }; 328 305 329 306 /* ICH10-based - Consumer/corporate versions have different amount of GPIO */ 330 307 static struct ichx_desc ich10_cons_desc = { 331 308 .ngpio = 61, 309 + .have_blink = true, 310 + .regs = ichx_regs, 311 + .reglen = ichx_reglen, 332 312 }; 333 313 static struct ichx_desc ich10_corp_desc = { 334 314 .ngpio = 72, 315 + .have_blink = true, 316 + .regs = ichx_regs, 317 + .reglen = ichx_reglen, 335 318 }; 336 319 337 320 /* Intel 5 series, 6 series, 3400 series, and C200 series */ 338 321 static struct ichx_desc intel5_desc = { 339 322 .ngpio = 76, 323 + .regs = ichx_regs, 324 + .reglen = ichx_reglen, 340 325 }; 341 326 342 327 static int ichx_gpio_request_regions(struct resource *res_base, ··· 361 318 if (!res_base || !res_base->start || !res_base->end) 362 319 return -ENODEV; 363 320 364 - for (i = 0; i < ARRAY_SIZE(ichx_regs[0]); i++) { 321 + for (i = 0; i < ARRAY_SIZE(ichx_priv.desc->regs[0]); i++) { 365 322 if (!(use_gpio & (1 << i))) 366 323 continue; 367 - if (!request_region(res_base->start + ichx_regs[0][i], 368 - ichx_reglen[i], name)) 324 + if (!request_region( 325 + res_base->start + ichx_priv.desc->regs[0][i], 326 + ichx_priv.desc->reglen[i], name)) 369 327 goto request_err; 370 328 } 371 329 return 0; ··· 376 332 for (i--; i >= 0; i--) { 377 333 if (!(use_gpio & (1 << i))) 378 334 continue; 379 - release_region(res_base->start + ichx_regs[0][i], 380 - ichx_reglen[i]); 335 + release_region(res_base->start + ichx_priv.desc->regs[0][i], 336 + ichx_priv.desc->reglen[i]); 381 337 } 382 338 return -EBUSY; 383 339 } ··· 386 342 { 387 343 int i; 388 344 389 - for (i = 0; i < ARRAY_SIZE(ichx_regs[0]); i++) { 345 + for (i = 0; i < ARRAY_SIZE(ichx_priv.desc->regs[0]); i++) { 390 346 if (!(use_gpio & (1 << i))) 391 347 continue; 392 - release_region(res_base->start + ichx_regs[0][i], 393 - ichx_reglen[i]); 348 + release_region(res_base->start + ichx_priv.desc->regs[0][i], 349 + ichx_priv.desc->reglen[i]); 394 350 } 395 351 } 396 352
+9 -13
drivers/gpio/gpio-intel-mid.c
··· 1 1 /* 2 - * Moorestown platform Langwell chip GPIO driver 2 + * Intel MID GPIO driver 3 3 * 4 - * Copyright (c) 2008, 2009, 2013, Intel Corporation. 4 + * Copyright (c) 2008-2014 Intel Corporation. 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License version 2 as ··· 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 * GNU General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the Free Software 17 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 14 */ 19 15 20 16 /* Supports: ··· 231 235 { 232 236 } 233 237 234 - static unsigned int intel_mid_irq_startup(struct irq_data *d) 238 + static int intel_mid_irq_reqres(struct irq_data *d) 235 239 { 236 240 struct intel_mid_gpio *priv = irq_data_get_irq_chip_data(d); 237 241 238 - if (gpio_lock_as_irq(&priv->chip, irqd_to_hwirq(d))) 242 + if (gpio_lock_as_irq(&priv->chip, irqd_to_hwirq(d))) { 239 243 dev_err(priv->chip.dev, 240 244 "unable to lock HW IRQ %lu for IRQ\n", 241 245 irqd_to_hwirq(d)); 242 - intel_mid_irq_unmask(d); 246 + return -EINVAL; 247 + } 243 248 return 0; 244 249 } 245 250 246 - static void intel_mid_irq_shutdown(struct irq_data *d) 251 + static void intel_mid_irq_relres(struct irq_data *d) 247 252 { 248 253 struct intel_mid_gpio *priv = irq_data_get_irq_chip_data(d); 249 254 250 - intel_mid_irq_mask(d); 251 255 gpio_unlock_as_irq(&priv->chip, irqd_to_hwirq(d)); 252 256 } 253 257 ··· 256 260 .irq_mask = intel_mid_irq_mask, 257 261 .irq_unmask = intel_mid_irq_unmask, 258 262 .irq_set_type = intel_mid_irq_type, 259 - .irq_startup = intel_mid_irq_startup, 260 - .irq_shutdown = intel_mid_irq_shutdown, 263 + .irq_request_resources = intel_mid_irq_reqres, 264 + .irq_release_resources = intel_mid_irq_relres, 261 265 }; 262 266 263 267 static const struct intel_mid_gpio_ddata gpio_lincroft = {
+2
drivers/gpio/gpio-iop.c
··· 111 111 112 112 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 113 113 base = devm_ioremap_resource(&pdev->dev, res); 114 + if (IS_ERR(base)) 115 + return PTR_ERR(base); 114 116 115 117 return gpiochip_add(&iop3xx_chip); 116 118 }
+8 -8
drivers/gpio/gpio-lynxpoint.c
··· 188 188 static int lp_gpio_get(struct gpio_chip *chip, unsigned offset) 189 189 { 190 190 unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); 191 - return inl(reg) & IN_LVL_BIT; 191 + return !!(inl(reg) & IN_LVL_BIT); 192 192 } 193 193 194 194 static void lp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ··· 301 301 spin_unlock_irqrestore(&lg->lock, flags); 302 302 } 303 303 304 - static unsigned int lp_irq_startup(struct irq_data *d) 304 + static int lp_irq_reqres(struct irq_data *d) 305 305 { 306 306 struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 307 307 308 - if (gpio_lock_as_irq(&lg->chip, irqd_to_hwirq(d))) 308 + if (gpio_lock_as_irq(&lg->chip, irqd_to_hwirq(d))) { 309 309 dev_err(lg->chip.dev, 310 310 "unable to lock HW IRQ %lu for IRQ\n", 311 311 irqd_to_hwirq(d)); 312 - lp_irq_enable(d); 312 + return -EINVAL; 313 + } 313 314 return 0; 314 315 } 315 316 316 - static void lp_irq_shutdown(struct irq_data *d) 317 + static void lp_irq_relres(struct irq_data *d) 317 318 { 318 319 struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 319 320 320 - lp_irq_disable(d); 321 321 gpio_unlock_as_irq(&lg->chip, irqd_to_hwirq(d)); 322 322 } 323 323 ··· 328 328 .irq_enable = lp_irq_enable, 329 329 .irq_disable = lp_irq_disable, 330 330 .irq_set_type = lp_irq_type, 331 - .irq_startup = lp_irq_startup, 332 - .irq_shutdown = lp_irq_shutdown, 331 + .irq_request_resources = lp_irq_reqres, 332 + .irq_release_resources = lp_irq_relres, 333 333 .flags = IRQCHIP_SKIP_SET_WAKE, 334 334 }; 335 335
+9
drivers/gpio/gpio-max732x.c
··· 622 622 goto out_failed; 623 623 } 624 624 625 + if (nr_port > 8 && !chip->client_dummy) { 626 + dev_err(&client->dev, 627 + "Failed to allocate second group I2C device\n"); 628 + ret = -ENODEV; 629 + goto out_failed; 630 + } 631 + 625 632 mutex_init(&chip->lock); 626 633 627 634 max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); ··· 654 647 return 0; 655 648 656 649 out_failed: 650 + if (chip->client_dummy) 651 + i2c_unregister_device(chip->client_dummy); 657 652 max732x_irq_teardown(chip); 658 653 return ret; 659 654 }
+18 -18
drivers/gpio/gpio-mcp23s08.c
··· 173 173 174 174 tx[0] = mcp->addr | 0x01; 175 175 tx[1] = reg; 176 - status = spi_write_then_read(mcp->data, tx, sizeof tx, rx, sizeof rx); 176 + status = spi_write_then_read(mcp->data, tx, sizeof(tx), rx, sizeof(rx)); 177 177 return (status < 0) ? status : rx[0]; 178 178 } 179 179 ··· 184 184 tx[0] = mcp->addr; 185 185 tx[1] = reg; 186 186 tx[2] = val; 187 - return spi_write_then_read(mcp->data, tx, sizeof tx, NULL, 0); 187 + return spi_write_then_read(mcp->data, tx, sizeof(tx), NULL, 0); 188 188 } 189 189 190 190 static int ··· 193 193 u8 tx[2], *tmp; 194 194 int status; 195 195 196 - if ((n + reg) > sizeof mcp->cache) 196 + if ((n + reg) > sizeof(mcp->cache)) 197 197 return -EINVAL; 198 198 tx[0] = mcp->addr | 0x01; 199 199 tx[1] = reg; 200 200 201 201 tmp = (u8 *)vals; 202 - status = spi_write_then_read(mcp->data, tx, sizeof tx, tmp, n); 202 + status = spi_write_then_read(mcp->data, tx, sizeof(tx), tmp, n); 203 203 if (status >= 0) { 204 204 while (n--) 205 205 vals[n] = tmp[n]; /* expand to 16bit */ ··· 214 214 215 215 tx[0] = mcp->addr | 0x01; 216 216 tx[1] = reg << 1; 217 - status = spi_write_then_read(mcp->data, tx, sizeof tx, rx, sizeof rx); 217 + status = spi_write_then_read(mcp->data, tx, sizeof(tx), rx, sizeof(rx)); 218 218 return (status < 0) ? status : (rx[0] | (rx[1] << 8)); 219 219 } 220 220 ··· 226 226 tx[1] = reg << 1; 227 227 tx[2] = val; 228 228 tx[3] = val >> 8; 229 - return spi_write_then_read(mcp->data, tx, sizeof tx, NULL, 0); 229 + return spi_write_then_read(mcp->data, tx, sizeof(tx), NULL, 0); 230 230 } 231 231 232 232 static int ··· 235 235 u8 tx[2]; 236 236 int status; 237 237 238 - if ((n + reg) > sizeof mcp->cache) 238 + if ((n + reg) > sizeof(mcp->cache)) 239 239 return -EINVAL; 240 240 tx[0] = mcp->addr | 0x01; 241 241 tx[1] = reg << 1; 242 242 243 - status = spi_write_then_read(mcp->data, tx, sizeof tx, 243 + status = spi_write_then_read(mcp->data, tx, sizeof(tx), 244 244 (u8 *)vals, n * 2); 245 245 if (status >= 0) { 246 246 while (n--) ··· 440 440 mutex_unlock(&mcp->irq_lock); 441 441 } 442 442 443 - static unsigned int mcp23s08_irq_startup(struct irq_data *data) 443 + static int mcp23s08_irq_reqres(struct irq_data *data) 444 444 { 445 445 struct mcp23s08 *mcp = irq_data_get_irq_chip_data(data); 446 446 447 - if (gpio_lock_as_irq(&mcp->chip, data->hwirq)) 447 + if (gpio_lock_as_irq(&mcp->chip, data->hwirq)) { 448 448 dev_err(mcp->chip.dev, 449 449 "unable to lock HW IRQ %lu for IRQ usage\n", 450 450 data->hwirq); 451 + return -EINVAL; 452 + } 451 453 452 - mcp23s08_irq_unmask(data); 453 454 return 0; 454 455 } 455 456 456 - static void mcp23s08_irq_shutdown(struct irq_data *data) 457 + static void mcp23s08_irq_relres(struct irq_data *data) 457 458 { 458 459 struct mcp23s08 *mcp = irq_data_get_irq_chip_data(data); 459 460 460 - mcp23s08_irq_mask(data); 461 461 gpio_unlock_as_irq(&mcp->chip, data->hwirq); 462 462 } 463 463 ··· 468 468 .irq_set_type = mcp23s08_irq_set_type, 469 469 .irq_bus_lock = mcp23s08_irq_bus_lock, 470 470 .irq_bus_sync_unlock = mcp23s08_irq_bus_unlock, 471 - .irq_startup = mcp23s08_irq_startup, 472 - .irq_shutdown = mcp23s08_irq_shutdown, 471 + .irq_request_resources = mcp23s08_irq_reqres, 472 + .irq_release_resources = mcp23s08_irq_relres, 473 473 }; 474 474 475 475 static int mcp23s08_irq_setup(struct mcp23s08 *mcp) ··· 567 567 (mcp->cache[MCP_GPIO] & mask) ? "hi" : "lo", 568 568 (mcp->cache[MCP_GPPU] & mask) ? "up" : " "); 569 569 /* NOTE: ignoring the irq-related registers */ 570 - seq_printf(s, "\n"); 570 + seq_puts(s, "\n"); 571 571 } 572 572 done: 573 573 mutex_unlock(&mcp->lock); ··· 789 789 pullups = pdata->chip[0].pullups; 790 790 } 791 791 792 - mcp = kzalloc(sizeof *mcp, GFP_KERNEL); 792 + mcp = kzalloc(sizeof(*mcp), GFP_KERNEL); 793 793 if (!mcp) 794 794 return -ENOMEM; 795 795 ··· 925 925 base = pdata->base; 926 926 } 927 927 928 - data = kzalloc(sizeof *data + chips * sizeof(struct mcp23s08), 928 + data = kzalloc(sizeof(*data) + chips * sizeof(struct mcp23s08), 929 929 GFP_KERNEL); 930 930 if (!data) 931 931 return -ENOMEM;
+26 -26
drivers/gpio/gpio-moxart.c
··· 48 48 pinctrl_free_gpio(offset); 49 49 } 50 50 51 + static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 52 + { 53 + struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 54 + void __iomem *ioaddr = gc->base + GPIO_DATA_OUT; 55 + u32 reg = readl(ioaddr); 56 + 57 + if (value) 58 + reg = reg | BIT(offset); 59 + else 60 + reg = reg & ~BIT(offset); 61 + 62 + writel(reg, ioaddr); 63 + } 64 + 65 + static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset) 66 + { 67 + struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 68 + u32 ret = readl(gc->base + GPIO_PIN_DIRECTION); 69 + 70 + if (ret & BIT(offset)) 71 + return !!(readl(gc->base + GPIO_DATA_OUT) & BIT(offset)); 72 + else 73 + return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset)); 74 + } 75 + 51 76 static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 52 77 { 53 78 struct moxart_gpio_chip *gc = to_moxart_gpio(chip); ··· 88 63 struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 89 64 void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION; 90 65 66 + moxart_gpio_set(chip, offset, value); 91 67 writel(readl(ioaddr) | BIT(offset), ioaddr); 92 68 return 0; 93 - } 94 - 95 - static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 96 - { 97 - struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 98 - void __iomem *ioaddr = gc->base + GPIO_DATA_OUT; 99 - u32 reg = readl(ioaddr); 100 - 101 - if (value) 102 - reg = reg | BIT(offset); 103 - else 104 - reg = reg & ~BIT(offset); 105 - 106 - 107 - writel(reg, ioaddr); 108 - } 109 - 110 - static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset) 111 - { 112 - struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 113 - u32 ret = readl(gc->base + GPIO_PIN_DIRECTION); 114 - 115 - if (ret & BIT(offset)) 116 - return !!(readl(gc->base + GPIO_DATA_OUT) & BIT(offset)); 117 - else 118 - return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset)); 119 69 } 120 70 121 71 static struct gpio_chip moxart_template_chip = {
+7
drivers/gpio/gpio-mvebu.c
··· 44 44 #include <linux/of_device.h> 45 45 #include <linux/clk.h> 46 46 #include <linux/pinctrl/consumer.h> 47 + #include <linux/irqchip/chained_irq.h> 47 48 48 49 /* 49 50 * GPIO unit register offsets. ··· 439 438 static void mvebu_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 440 439 { 441 440 struct mvebu_gpio_chip *mvchip = irq_get_handler_data(irq); 441 + struct irq_chip *chip = irq_desc_get_chip(desc); 442 442 u32 cause, type; 443 443 int i; 444 444 445 445 if (mvchip == NULL) 446 446 return; 447 + 448 + chained_irq_enter(chip, desc); 447 449 448 450 cause = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) & 449 451 readl_relaxed(mvebu_gpioreg_level_mask(mvchip)); ··· 470 466 polarity ^= 1 << i; 471 467 writel_relaxed(polarity, mvebu_gpioreg_in_pol(mvchip)); 472 468 } 469 + 473 470 generic_handle_irq(irq); 474 471 } 472 + 473 + chained_irq_exit(chip, desc); 475 474 } 476 475 477 476 #ifdef CONFIG_DEBUG_FS
+2 -1
drivers/gpio/gpio-mxs.c
··· 214 214 ct->regs.ack = PINCTRL_IRQSTAT(port) + MXS_CLR; 215 215 ct->regs.mask = PINCTRL_IRQEN(port); 216 216 217 - irq_setup_generic_chip(gc, IRQ_MSK(32), 0, IRQ_NOREQUEST, 0); 217 + irq_setup_generic_chip(gc, IRQ_MSK(32), IRQ_GC_INIT_NESTED_LOCK, 218 + IRQ_NOREQUEST, 0); 218 219 } 219 220 220 221 static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
+3 -17
drivers/gpio/gpio-omap.c
··· 1214 1214 1215 1215 /* Static mapping, never released */ 1216 1216 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1217 - if (unlikely(!res)) { 1218 - dev_err(dev, "Invalid mem resource\n"); 1217 + bank->base = devm_ioremap_resource(dev, res); 1218 + if (IS_ERR(bank->base)) { 1219 1219 irq_domain_remove(bank->domain); 1220 - return -ENODEV; 1221 - } 1222 - 1223 - if (!devm_request_mem_region(dev, res->start, resource_size(res), 1224 - pdev->name)) { 1225 - dev_err(dev, "Region already claimed\n"); 1226 - irq_domain_remove(bank->domain); 1227 - return -EBUSY; 1228 - } 1229 - 1230 - bank->base = devm_ioremap(dev, res->start, resource_size(res)); 1231 - if (!bank->base) { 1232 - dev_err(dev, "Could not ioremap\n"); 1233 - irq_domain_remove(bank->domain); 1234 - return -ENOMEM; 1220 + return PTR_ERR(bank->base); 1235 1221 } 1236 1222 1237 1223 platform_set_drvdata(pdev, bank);
+8 -2
drivers/gpio/gpio-pca953x.c
··· 1 1 /* 2 - * PCA953x 4/8/16 bit I/O ports 2 + * PCA953x 4/8/16/24/40 bit I/O ports 3 3 * 4 4 * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> 5 5 * Copyright (C) 2007 Marvell International Ltd. ··· 59 59 { "pca9557", 8 | PCA953X_TYPE, }, 60 60 { "pca9574", 8 | PCA957X_TYPE | PCA_INT, }, 61 61 { "pca9575", 16 | PCA957X_TYPE | PCA_INT, }, 62 + { "pca9698", 40 | PCA953X_TYPE, }, 62 63 63 64 { "max7310", 8 | PCA953X_TYPE, }, 64 65 { "max7312", 16 | PCA953X_TYPE | PCA_INT, }, ··· 69 68 { "tca6408", 8 | PCA953X_TYPE | PCA_INT, }, 70 69 { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, 71 70 { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, 71 + { "xra1202", 8 | PCA953X_TYPE }, 72 72 { } 73 73 }; 74 74 MODULE_DEVICE_TABLE(i2c, pca953x_id); ··· 627 625 const __be32 *val; 628 626 int size; 629 627 628 + *gpio_base = -1; 629 + 630 630 node = client->dev.of_node; 631 631 if (node == NULL) 632 632 return; 633 633 634 - *gpio_base = -1; 635 634 val = of_get_property(node, "linux,gpio-base", &size); 636 635 WARN(val, "%s: device-tree property 'linux,gpio-base' is deprecated!", __func__); 637 636 if (val) { ··· 815 812 { .compatible = "nxp,pca9557", }, 816 813 { .compatible = "nxp,pca9574", }, 817 814 { .compatible = "nxp,pca9575", }, 815 + { .compatible = "nxp,pca9698", }, 818 816 819 817 { .compatible = "maxim,max7310", }, 820 818 { .compatible = "maxim,max7312", }, ··· 826 822 { .compatible = "ti,tca6408", }, 827 823 { .compatible = "ti,tca6416", }, 828 824 { .compatible = "ti,tca6424", }, 825 + 826 + { .compatible = "exar,xra1202", }, 829 827 { } 830 828 }; 831 829
+5 -3
drivers/gpio/gpio-pch.c
··· 138 138 unsigned long flags; 139 139 140 140 spin_lock_irqsave(&chip->spinlock, flags); 141 - pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); 142 - pm |= (1 << nr); 143 - iowrite32(pm, &chip->reg->pm); 144 141 145 142 reg_val = ioread32(&chip->reg->po); 146 143 if (val) ··· 145 148 else 146 149 reg_val &= ~(1 << nr); 147 150 iowrite32(reg_val, &chip->reg->po); 151 + 152 + pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); 153 + pm |= (1 << nr); 154 + iowrite32(pm, &chip->reg->pm); 155 + 148 156 spin_unlock_irqrestore(&chip->spinlock, flags); 149 157 150 158 return 0;
+54 -72
drivers/gpio/gpio-pl061.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/ioport.h> 17 17 #include <linux/irq.h> 18 - #include <linux/irqdomain.h> 19 18 #include <linux/irqchip/chained_irq.h> 20 19 #include <linux/bitops.h> 21 20 #include <linux/workqueue.h> ··· 52 53 spinlock_t lock; 53 54 54 55 void __iomem *base; 55 - struct irq_domain *domain; 56 56 struct gpio_chip gc; 57 57 58 58 #ifdef CONFIG_PM ··· 135 137 writeb(!!value << offset, chip->base + (1 << (offset + 2))); 136 138 } 137 139 138 - static int pl061_to_irq(struct gpio_chip *gc, unsigned offset) 139 - { 140 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 141 - 142 - return irq_create_mapping(chip->domain, offset); 143 - } 144 - 145 140 static int pl061_irq_type(struct irq_data *d, unsigned trigger) 146 141 { 147 - struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); 142 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 143 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 148 144 int offset = irqd_to_hwirq(d); 149 145 unsigned long flags; 150 146 u8 gpiois, gpioibe, gpioiev; 147 + u8 bit = BIT(offset); 151 148 152 149 if (offset < 0 || offset >= PL061_GPIO_NR) 153 150 return -EINVAL; ··· 150 157 spin_lock_irqsave(&chip->lock, flags); 151 158 152 159 gpioiev = readb(chip->base + GPIOIEV); 153 - 154 160 gpiois = readb(chip->base + GPIOIS); 155 - if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 156 - gpiois |= 1 << offset; 157 - if (trigger & IRQ_TYPE_LEVEL_HIGH) 158 - gpioiev |= 1 << offset; 159 - else 160 - gpioiev &= ~(1 << offset); 161 - } else 162 - gpiois &= ~(1 << offset); 163 - writeb(gpiois, chip->base + GPIOIS); 164 - 165 161 gpioibe = readb(chip->base + GPIOIBE); 166 - if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 167 - gpioibe |= 1 << offset; 168 - else { 169 - gpioibe &= ~(1 << offset); 170 - if (trigger & IRQ_TYPE_EDGE_RISING) 171 - gpioiev |= 1 << offset; 172 - else if (trigger & IRQ_TYPE_EDGE_FALLING) 173 - gpioiev &= ~(1 << offset); 174 - } 175 - writeb(gpioibe, chip->base + GPIOIBE); 176 162 163 + if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 164 + gpiois |= bit; 165 + if (trigger & IRQ_TYPE_LEVEL_HIGH) 166 + gpioiev |= bit; 167 + else 168 + gpioiev &= ~bit; 169 + } else 170 + gpiois &= ~bit; 171 + 172 + if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 173 + /* Setting this makes GPIOEV be ignored */ 174 + gpioibe |= bit; 175 + else { 176 + gpioibe &= ~bit; 177 + if (trigger & IRQ_TYPE_EDGE_RISING) 178 + gpioiev |= bit; 179 + else if (trigger & IRQ_TYPE_EDGE_FALLING) 180 + gpioiev &= ~bit; 181 + } 182 + 183 + writeb(gpiois, chip->base + GPIOIS); 184 + writeb(gpioibe, chip->base + GPIOIBE); 177 185 writeb(gpioiev, chip->base + GPIOIEV); 178 186 179 187 spin_unlock_irqrestore(&chip->lock, flags); ··· 186 192 { 187 193 unsigned long pending; 188 194 int offset; 189 - struct pl061_gpio *chip = irq_desc_get_handler_data(desc); 195 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 196 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 190 197 struct irq_chip *irqchip = irq_desc_get_chip(desc); 191 198 192 199 chained_irq_enter(irqchip, desc); ··· 196 201 writeb(pending, chip->base + GPIOIC); 197 202 if (pending) { 198 203 for_each_set_bit(offset, &pending, PL061_GPIO_NR) 199 - generic_handle_irq(pl061_to_irq(&chip->gc, offset)); 204 + generic_handle_irq(irq_find_mapping(gc->irqdomain, 205 + offset)); 200 206 } 201 207 202 208 chained_irq_exit(irqchip, desc); ··· 205 209 206 210 static void pl061_irq_mask(struct irq_data *d) 207 211 { 208 - struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); 212 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 213 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 209 214 u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); 210 215 u8 gpioie; 211 216 ··· 218 221 219 222 static void pl061_irq_unmask(struct irq_data *d) 220 223 { 221 - struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); 224 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 225 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 222 226 u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); 223 227 u8 gpioie; 224 228 ··· 230 232 } 231 233 232 234 static struct irq_chip pl061_irqchip = { 233 - .name = "pl061 gpio", 235 + .name = "pl061", 234 236 .irq_mask = pl061_irq_mask, 235 237 .irq_unmask = pl061_irq_unmask, 236 238 .irq_set_type = pl061_irq_type, 237 - }; 238 - 239 - static int pl061_irq_map(struct irq_domain *d, unsigned int irq, 240 - irq_hw_number_t hwirq) 241 - { 242 - struct pl061_gpio *chip = d->host_data; 243 - 244 - irq_set_chip_and_handler_name(irq, &pl061_irqchip, handle_simple_irq, 245 - "pl061"); 246 - irq_set_chip_data(irq, chip); 247 - irq_set_irq_type(irq, IRQ_TYPE_NONE); 248 - 249 - return 0; 250 - } 251 - 252 - static const struct irq_domain_ops pl061_domain_ops = { 253 - .map = pl061_irq_map, 254 - .xlate = irq_domain_xlate_twocell, 255 239 }; 256 240 257 241 static int pl061_probe(struct amba_device *adev, const struct amba_id *id) ··· 250 270 if (pdata) { 251 271 chip->gc.base = pdata->gpio_base; 252 272 irq_base = pdata->irq_base; 253 - if (irq_base <= 0) 273 + if (irq_base <= 0) { 274 + dev_err(&adev->dev, "invalid IRQ base in pdata\n"); 254 275 return -ENODEV; 276 + } 255 277 } else { 256 278 chip->gc.base = -1; 257 279 irq_base = 0; 258 280 } 259 281 260 - if (!devm_request_mem_region(dev, adev->res.start, 261 - resource_size(&adev->res), "pl061")) 262 - return -EBUSY; 263 - 264 - chip->base = devm_ioremap(dev, adev->res.start, 265 - resource_size(&adev->res)); 266 - if (!chip->base) 267 - return -ENOMEM; 282 + chip->base = devm_ioremap_resource(dev, &adev->res); 283 + if (IS_ERR(chip->base)) 284 + return PTR_ERR(chip->base); 268 285 269 286 spin_lock_init(&chip->lock); 270 287 ··· 271 294 chip->gc.direction_output = pl061_direction_output; 272 295 chip->gc.get = pl061_get_value; 273 296 chip->gc.set = pl061_set_value; 274 - chip->gc.to_irq = pl061_to_irq; 275 297 chip->gc.ngpio = PL061_GPIO_NR; 276 298 chip->gc.label = dev_name(dev); 277 299 chip->gc.dev = dev; ··· 285 309 */ 286 310 writeb(0, chip->base + GPIOIE); /* disable irqs */ 287 311 irq = adev->irq[0]; 288 - if (irq < 0) 312 + if (irq < 0) { 313 + dev_err(&adev->dev, "invalid IRQ\n"); 289 314 return -ENODEV; 315 + } 290 316 291 - irq_set_chained_handler(irq, pl061_irq_handler); 292 - irq_set_handler_data(irq, chip); 293 - 294 - chip->domain = irq_domain_add_simple(adev->dev.of_node, PL061_GPIO_NR, 295 - irq_base, &pl061_domain_ops, chip); 296 - if (!chip->domain) 297 - return -ENODEV; 317 + ret = gpiochip_irqchip_add(&chip->gc, &pl061_irqchip, 318 + irq_base, handle_simple_irq, 319 + IRQ_TYPE_NONE); 320 + if (ret) { 321 + dev_info(&adev->dev, "could not add irqchip\n"); 322 + return ret; 323 + } 324 + gpiochip_set_chained_irqchip(&chip->gc, &pl061_irqchip, 325 + irq, pl061_irq_handler); 298 326 299 327 for (i = 0; i < PL061_GPIO_NR; i++) { 300 328 if (pdata) { ··· 311 331 } 312 332 313 333 amba_set_drvdata(adev, chip); 334 + dev_info(&adev->dev, "PL061 GPIO chip @%pa registered\n", 335 + &adev->res.start); 314 336 315 337 return 0; 316 338 }
+1 -1
drivers/gpio/gpio-rc5t583.c
··· 97 97 { 98 98 struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 99 99 100 - if ((offset >= 0) && (offset < 8)) 100 + if (offset < RC5T583_MAX_GPIO) 101 101 return rc5t583_gpio->rc5t583->irq_base + 102 102 RC5T583_IRQ_GPIO0 + offset; 103 103 return -EINVAL;
+16 -16
drivers/gpio/gpio-rcar.c
··· 356 356 struct resource *io, *irq; 357 357 struct gpio_chip *gpio_chip; 358 358 struct irq_chip *irq_chip; 359 - const char *name = dev_name(&pdev->dev); 359 + struct device *dev = &pdev->dev; 360 + const char *name = dev_name(dev); 360 361 int ret; 361 362 362 - p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); 363 + p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); 363 364 if (!p) { 364 - dev_err(&pdev->dev, "failed to allocate driver data\n"); 365 + dev_err(dev, "failed to allocate driver data\n"); 365 366 ret = -ENOMEM; 366 367 goto err0; 367 368 } ··· 381 380 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 382 381 383 382 if (!io || !irq) { 384 - dev_err(&pdev->dev, "missing IRQ or IOMEM\n"); 383 + dev_err(dev, "missing IRQ or IOMEM\n"); 385 384 ret = -EINVAL; 386 385 goto err0; 387 386 } 388 387 389 - p->base = devm_ioremap_nocache(&pdev->dev, io->start, 390 - resource_size(io)); 388 + p->base = devm_ioremap_nocache(dev, io->start, resource_size(io)); 391 389 if (!p->base) { 392 - dev_err(&pdev->dev, "failed to remap I/O memory\n"); 390 + dev_err(dev, "failed to remap I/O memory\n"); 393 391 ret = -ENXIO; 394 392 goto err0; 395 393 } ··· 402 402 gpio_chip->set = gpio_rcar_set; 403 403 gpio_chip->to_irq = gpio_rcar_to_irq; 404 404 gpio_chip->label = name; 405 - gpio_chip->dev = &pdev->dev; 405 + gpio_chip->dev = dev; 406 406 gpio_chip->owner = THIS_MODULE; 407 407 gpio_chip->base = p->config.gpio_base; 408 408 gpio_chip->ngpio = p->config.number_of_pins; ··· 421 421 &gpio_rcar_irq_domain_ops, p); 422 422 if (!p->irq_domain) { 423 423 ret = -ENXIO; 424 - dev_err(&pdev->dev, "cannot initialize irq domain\n"); 424 + dev_err(dev, "cannot initialize irq domain\n"); 425 425 goto err0; 426 426 } 427 427 428 - if (devm_request_irq(&pdev->dev, irq->start, 429 - gpio_rcar_irq_handler, IRQF_SHARED, name, p)) { 430 - dev_err(&pdev->dev, "failed to request IRQ\n"); 428 + if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler, 429 + IRQF_SHARED, name, p)) { 430 + dev_err(dev, "failed to request IRQ\n"); 431 431 ret = -ENOENT; 432 432 goto err1; 433 433 } 434 434 435 435 ret = gpiochip_add(gpio_chip); 436 436 if (ret) { 437 - dev_err(&pdev->dev, "failed to add GPIO controller\n"); 437 + dev_err(dev, "failed to add GPIO controller\n"); 438 438 goto err1; 439 439 } 440 440 441 - dev_info(&pdev->dev, "driving %d GPIOs\n", p->config.number_of_pins); 441 + dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins); 442 442 443 443 /* warn in case of mismatch if irq base is specified */ 444 444 if (p->config.irq_base) { 445 445 ret = irq_find_mapping(p->irq_domain, 0); 446 446 if (p->config.irq_base != ret) 447 - dev_warn(&pdev->dev, "irq base mismatch (%u/%u)\n", 447 + dev_warn(dev, "irq base mismatch (%u/%u)\n", 448 448 p->config.irq_base, ret); 449 449 } 450 450 ··· 452 452 ret = gpiochip_add_pin_range(gpio_chip, p->config.pctl_name, 0, 453 453 gpio_chip->base, gpio_chip->ngpio); 454 454 if (ret < 0) 455 - dev_warn(&pdev->dev, "failed to add pin range\n"); 455 + dev_warn(dev, "failed to add pin range\n"); 456 456 } 457 457 458 458 return 0;
+1
drivers/gpio/gpio-samsung.c
··· 379 379 case 6: 380 380 shift = ((off + 1) & 7) * 4; 381 381 reg -= 4; 382 + break; 382 383 default: 383 384 shift = ((off + 1) & 7) * 4; 384 385 break;
+191
drivers/gpio/gpio-syscon.c
··· 1 + /* 2 + * SYSCON 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.h> 16 + #include <linux/of_device.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/regmap.h> 19 + #include <linux/mfd/syscon.h> 20 + 21 + #define GPIO_SYSCON_FEAT_IN BIT(0) 22 + #define GPIO_SYSCON_FEAT_OUT BIT(1) 23 + #define GPIO_SYSCON_FEAT_DIR BIT(2) 24 + 25 + /* SYSCON driver is designed to use 32-bit wide registers */ 26 + #define SYSCON_REG_SIZE (4) 27 + #define SYSCON_REG_BITS (SYSCON_REG_SIZE * 8) 28 + 29 + /** 30 + * struct syscon_gpio_data - Configuration for the device. 31 + * compatible: SYSCON driver compatible string. 32 + * flags: Set of GPIO_SYSCON_FEAT_ flags: 33 + * GPIO_SYSCON_FEAT_IN: GPIOs supports input, 34 + * GPIO_SYSCON_FEAT_OUT: GPIOs supports output, 35 + * GPIO_SYSCON_FEAT_DIR: GPIOs supports switch direction. 36 + * bit_count: Number of bits used as GPIOs. 37 + * dat_bit_offset: Offset (in bits) to the first GPIO bit. 38 + * dir_bit_offset: Optional offset (in bits) to the first bit to switch 39 + * GPIO direction (Used with GPIO_SYSCON_FEAT_DIR flag). 40 + */ 41 + 42 + struct syscon_gpio_data { 43 + const char *compatible; 44 + unsigned int flags; 45 + unsigned int bit_count; 46 + unsigned int dat_bit_offset; 47 + unsigned int dir_bit_offset; 48 + }; 49 + 50 + struct syscon_gpio_priv { 51 + struct gpio_chip chip; 52 + struct regmap *syscon; 53 + const struct syscon_gpio_data *data; 54 + }; 55 + 56 + static inline struct syscon_gpio_priv *to_syscon_gpio(struct gpio_chip *chip) 57 + { 58 + return container_of(chip, struct syscon_gpio_priv, chip); 59 + } 60 + 61 + static int syscon_gpio_get(struct gpio_chip *chip, unsigned offset) 62 + { 63 + struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 64 + unsigned int val, offs = priv->data->dat_bit_offset + offset; 65 + int ret; 66 + 67 + ret = regmap_read(priv->syscon, 68 + (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, &val); 69 + if (ret) 70 + return ret; 71 + 72 + return !!(val & BIT(offs % SYSCON_REG_BITS)); 73 + } 74 + 75 + static void syscon_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 76 + { 77 + struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 78 + unsigned int offs = priv->data->dat_bit_offset + offset; 79 + 80 + regmap_update_bits(priv->syscon, 81 + (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, 82 + BIT(offs % SYSCON_REG_BITS), 83 + val ? BIT(offs % SYSCON_REG_BITS) : 0); 84 + } 85 + 86 + static int syscon_gpio_dir_in(struct gpio_chip *chip, unsigned offset) 87 + { 88 + struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 89 + 90 + if (priv->data->flags & GPIO_SYSCON_FEAT_DIR) { 91 + unsigned int offs = priv->data->dir_bit_offset + offset; 92 + 93 + regmap_update_bits(priv->syscon, 94 + (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, 95 + BIT(offs % SYSCON_REG_BITS), 0); 96 + } 97 + 98 + return 0; 99 + } 100 + 101 + static int syscon_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int val) 102 + { 103 + struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 104 + 105 + if (priv->data->flags & GPIO_SYSCON_FEAT_DIR) { 106 + unsigned int offs = priv->data->dir_bit_offset + offset; 107 + 108 + regmap_update_bits(priv->syscon, 109 + (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, 110 + BIT(offs % SYSCON_REG_BITS), 111 + BIT(offs % SYSCON_REG_BITS)); 112 + } 113 + 114 + syscon_gpio_set(chip, offset, val); 115 + 116 + return 0; 117 + } 118 + 119 + static const struct syscon_gpio_data clps711x_mctrl_gpio = { 120 + /* ARM CLPS711X SYSFLG1 Bits 8-10 */ 121 + .compatible = "cirrus,clps711x-syscon1", 122 + .flags = GPIO_SYSCON_FEAT_IN, 123 + .bit_count = 3, 124 + .dat_bit_offset = 0x40 * 8 + 8, 125 + }; 126 + 127 + static const struct of_device_id syscon_gpio_ids[] = { 128 + { 129 + .compatible = "cirrus,clps711x-mctrl-gpio", 130 + .data = &clps711x_mctrl_gpio, 131 + }, 132 + { } 133 + }; 134 + MODULE_DEVICE_TABLE(of, syscon_gpio_ids); 135 + 136 + static int syscon_gpio_probe(struct platform_device *pdev) 137 + { 138 + struct device *dev = &pdev->dev; 139 + const struct of_device_id *of_id = of_match_device(syscon_gpio_ids, dev); 140 + struct syscon_gpio_priv *priv; 141 + 142 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 143 + if (!priv) 144 + return -ENOMEM; 145 + 146 + priv->data = of_id->data; 147 + 148 + priv->syscon = 149 + syscon_regmap_lookup_by_compatible(priv->data->compatible); 150 + if (IS_ERR(priv->syscon)) 151 + return PTR_ERR(priv->syscon); 152 + 153 + priv->chip.dev = dev; 154 + priv->chip.owner = THIS_MODULE; 155 + priv->chip.label = dev_name(dev); 156 + priv->chip.base = -1; 157 + priv->chip.ngpio = priv->data->bit_count; 158 + priv->chip.get = syscon_gpio_get; 159 + if (priv->data->flags & GPIO_SYSCON_FEAT_IN) 160 + priv->chip.direction_input = syscon_gpio_dir_in; 161 + if (priv->data->flags & GPIO_SYSCON_FEAT_OUT) { 162 + priv->chip.set = syscon_gpio_set; 163 + priv->chip.direction_output = syscon_gpio_dir_out; 164 + } 165 + 166 + platform_set_drvdata(pdev, priv); 167 + 168 + return gpiochip_add(&priv->chip); 169 + } 170 + 171 + static int syscon_gpio_remove(struct platform_device *pdev) 172 + { 173 + struct syscon_gpio_priv *priv = platform_get_drvdata(pdev); 174 + 175 + return gpiochip_remove(&priv->chip); 176 + } 177 + 178 + static struct platform_driver syscon_gpio_driver = { 179 + .driver = { 180 + .name = "gpio-syscon", 181 + .owner = THIS_MODULE, 182 + .of_match_table = syscon_gpio_ids, 183 + }, 184 + .probe = syscon_gpio_probe, 185 + .remove = syscon_gpio_remove, 186 + }; 187 + module_platform_driver(syscon_gpio_driver); 188 + 189 + MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>"); 190 + MODULE_DESCRIPTION("SYSCON GPIO driver"); 191 + MODULE_LICENSE("GPL");
-206
drivers/gpio/gpio-tnetv107x.c
··· 1 - /* 2 - * Texas Instruments TNETV107X GPIO Controller 3 - * 4 - * Copyright (C) 2010 Texas Instruments 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License as 8 - * published by the Free Software Foundation version 2. 9 - * 10 - * This program is distributed "as is" WITHOUT ANY WARRANTY of any 11 - * kind, whether express or implied; without even the implied warranty 12 - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - * GNU General Public License for more details. 14 - */ 15 - #include <linux/kernel.h> 16 - #include <linux/init.h> 17 - #include <linux/gpio.h> 18 - #include <linux/platform_data/gpio-davinci.h> 19 - 20 - #include <mach/common.h> 21 - #include <mach/tnetv107x.h> 22 - 23 - struct tnetv107x_gpio_regs { 24 - u32 idver; 25 - u32 data_in[3]; 26 - u32 data_out[3]; 27 - u32 direction[3]; 28 - u32 enable[3]; 29 - }; 30 - 31 - #define gpio_reg_index(gpio) ((gpio) >> 5) 32 - #define gpio_reg_bit(gpio) BIT((gpio) & 0x1f) 33 - 34 - #define gpio_reg_rmw(reg, mask, val) \ 35 - __raw_writel((__raw_readl(reg) & ~(mask)) | (val), (reg)) 36 - 37 - #define gpio_reg_set_bit(reg, gpio) \ 38 - gpio_reg_rmw((reg) + gpio_reg_index(gpio), 0, gpio_reg_bit(gpio)) 39 - 40 - #define gpio_reg_clear_bit(reg, gpio) \ 41 - gpio_reg_rmw((reg) + gpio_reg_index(gpio), gpio_reg_bit(gpio), 0) 42 - 43 - #define gpio_reg_get_bit(reg, gpio) \ 44 - (__raw_readl((reg) + gpio_reg_index(gpio)) & gpio_reg_bit(gpio)) 45 - 46 - #define chip2controller(chip) \ 47 - container_of(chip, struct davinci_gpio_controller, chip) 48 - 49 - #define TNETV107X_GPIO_CTLRS DIV_ROUND_UP(TNETV107X_N_GPIO, 32) 50 - 51 - static struct davinci_gpio_controller chips[TNETV107X_GPIO_CTLRS]; 52 - 53 - static int tnetv107x_gpio_request(struct gpio_chip *chip, unsigned offset) 54 - { 55 - struct davinci_gpio_controller *ctlr = chip2controller(chip); 56 - struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; 57 - unsigned gpio = chip->base + offset; 58 - unsigned long flags; 59 - 60 - spin_lock_irqsave(&ctlr->lock, flags); 61 - 62 - gpio_reg_set_bit(regs->enable, gpio); 63 - 64 - spin_unlock_irqrestore(&ctlr->lock, flags); 65 - 66 - return 0; 67 - } 68 - 69 - static void tnetv107x_gpio_free(struct gpio_chip *chip, unsigned offset) 70 - { 71 - struct davinci_gpio_controller *ctlr = chip2controller(chip); 72 - struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; 73 - unsigned gpio = chip->base + offset; 74 - unsigned long flags; 75 - 76 - spin_lock_irqsave(&ctlr->lock, flags); 77 - 78 - gpio_reg_clear_bit(regs->enable, gpio); 79 - 80 - spin_unlock_irqrestore(&ctlr->lock, flags); 81 - } 82 - 83 - static int tnetv107x_gpio_dir_in(struct gpio_chip *chip, unsigned offset) 84 - { 85 - struct davinci_gpio_controller *ctlr = chip2controller(chip); 86 - struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; 87 - unsigned gpio = chip->base + offset; 88 - unsigned long flags; 89 - 90 - spin_lock_irqsave(&ctlr->lock, flags); 91 - 92 - gpio_reg_set_bit(regs->direction, gpio); 93 - 94 - spin_unlock_irqrestore(&ctlr->lock, flags); 95 - 96 - return 0; 97 - } 98 - 99 - static int tnetv107x_gpio_dir_out(struct gpio_chip *chip, 100 - unsigned offset, int value) 101 - { 102 - struct davinci_gpio_controller *ctlr = chip2controller(chip); 103 - struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; 104 - unsigned gpio = chip->base + offset; 105 - unsigned long flags; 106 - 107 - spin_lock_irqsave(&ctlr->lock, flags); 108 - 109 - if (value) 110 - gpio_reg_set_bit(regs->data_out, gpio); 111 - else 112 - gpio_reg_clear_bit(regs->data_out, gpio); 113 - 114 - gpio_reg_clear_bit(regs->direction, gpio); 115 - 116 - spin_unlock_irqrestore(&ctlr->lock, flags); 117 - 118 - return 0; 119 - } 120 - 121 - static int tnetv107x_gpio_get(struct gpio_chip *chip, unsigned offset) 122 - { 123 - struct davinci_gpio_controller *ctlr = chip2controller(chip); 124 - struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; 125 - unsigned gpio = chip->base + offset; 126 - int ret; 127 - 128 - ret = gpio_reg_get_bit(regs->data_in, gpio); 129 - 130 - return ret ? 1 : 0; 131 - } 132 - 133 - static void tnetv107x_gpio_set(struct gpio_chip *chip, 134 - unsigned offset, int value) 135 - { 136 - struct davinci_gpio_controller *ctlr = chip2controller(chip); 137 - struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; 138 - unsigned gpio = chip->base + offset; 139 - unsigned long flags; 140 - 141 - spin_lock_irqsave(&ctlr->lock, flags); 142 - 143 - if (value) 144 - gpio_reg_set_bit(regs->data_out, gpio); 145 - else 146 - gpio_reg_clear_bit(regs->data_out, gpio); 147 - 148 - spin_unlock_irqrestore(&ctlr->lock, flags); 149 - } 150 - 151 - static int __init tnetv107x_gpio_setup(void) 152 - { 153 - int i, base; 154 - unsigned ngpio; 155 - struct davinci_soc_info *soc_info = &davinci_soc_info; 156 - struct tnetv107x_gpio_regs *regs; 157 - struct davinci_gpio_controller *ctlr; 158 - 159 - if (soc_info->gpio_type != GPIO_TYPE_TNETV107X) 160 - return 0; 161 - 162 - ngpio = soc_info->gpio_num; 163 - if (ngpio == 0) { 164 - pr_err("GPIO setup: how many GPIOs?\n"); 165 - return -EINVAL; 166 - } 167 - 168 - if (WARN_ON(TNETV107X_N_GPIO < ngpio)) 169 - ngpio = TNETV107X_N_GPIO; 170 - 171 - regs = ioremap(soc_info->gpio_base, SZ_4K); 172 - if (WARN_ON(!regs)) 173 - return -EINVAL; 174 - 175 - for (i = 0, base = 0; base < ngpio; i++, base += 32) { 176 - ctlr = &chips[i]; 177 - 178 - ctlr->chip.label = "tnetv107x"; 179 - ctlr->chip.can_sleep = false; 180 - ctlr->chip.base = base; 181 - ctlr->chip.ngpio = ngpio - base; 182 - if (ctlr->chip.ngpio > 32) 183 - ctlr->chip.ngpio = 32; 184 - 185 - ctlr->chip.request = tnetv107x_gpio_request; 186 - ctlr->chip.free = tnetv107x_gpio_free; 187 - ctlr->chip.direction_input = tnetv107x_gpio_dir_in; 188 - ctlr->chip.get = tnetv107x_gpio_get; 189 - ctlr->chip.direction_output = tnetv107x_gpio_dir_out; 190 - ctlr->chip.set = tnetv107x_gpio_set; 191 - 192 - spin_lock_init(&ctlr->lock); 193 - 194 - ctlr->regs = regs; 195 - ctlr->set_data = &regs->data_out[i]; 196 - ctlr->clr_data = &regs->data_out[i]; 197 - ctlr->in_data = &regs->data_in[i]; 198 - 199 - gpiochip_add(&ctlr->chip); 200 - } 201 - 202 - soc_info->gpio_ctlrs = chips; 203 - soc_info->gpio_ctlrs_num = DIV_ROUND_UP(ngpio, 32); 204 - return 0; 205 - } 206 - pure_initcall(tnetv107x_gpio_setup);
+3 -3
drivers/gpio/gpio-twl4030.c
··· 139 139 static void twl4030_led_set_value(int led, int value) 140 140 { 141 141 u8 mask = LEDEN_LEDAON | LEDEN_LEDAPWM; 142 - int status; 143 142 144 143 if (led) 145 144 mask <<= 1; ··· 147 148 cached_leden &= ~mask; 148 149 else 149 150 cached_leden |= mask; 150 - status = twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden, 151 - TWL4030_LED_LEDEN_REG); 151 + 152 + WARN_ON_ONCE(twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden, 153 + TWL4030_LED_LEDEN_REG)); 152 154 } 153 155 154 156 static int twl4030_set_gpio_direction(int gpio, int is_input)
+14 -14
drivers/gpio/gpio-tz1090.c
··· 488 488 gc->chip_types[0].handler = handle_level_irq; 489 489 gc->chip_types[0].regs.ack = REG_GPIO_IRQ_STS; 490 490 gc->chip_types[0].regs.mask = REG_GPIO_IRQ_EN; 491 - gc->chip_types[0].chip.irq_startup = gpio_startup_irq, 492 - gc->chip_types[0].chip.irq_ack = irq_gc_ack_clr_bit, 493 - gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit, 494 - gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit, 495 - gc->chip_types[0].chip.irq_set_type = gpio_set_irq_type, 496 - gc->chip_types[0].chip.irq_set_wake = gpio_set_irq_wake, 497 - gc->chip_types[0].chip.flags = IRQCHIP_MASK_ON_SUSPEND, 491 + gc->chip_types[0].chip.irq_startup = gpio_startup_irq; 492 + gc->chip_types[0].chip.irq_ack = irq_gc_ack_clr_bit; 493 + gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit; 494 + gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit; 495 + gc->chip_types[0].chip.irq_set_type = gpio_set_irq_type; 496 + gc->chip_types[0].chip.irq_set_wake = gpio_set_irq_wake; 497 + gc->chip_types[0].chip.flags = IRQCHIP_MASK_ON_SUSPEND; 498 498 499 499 /* edge chip type */ 500 500 gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH; 501 501 gc->chip_types[1].handler = handle_edge_irq; 502 502 gc->chip_types[1].regs.ack = REG_GPIO_IRQ_STS; 503 503 gc->chip_types[1].regs.mask = REG_GPIO_IRQ_EN; 504 - gc->chip_types[1].chip.irq_startup = gpio_startup_irq, 505 - gc->chip_types[1].chip.irq_ack = irq_gc_ack_clr_bit, 506 - gc->chip_types[1].chip.irq_mask = irq_gc_mask_clr_bit, 507 - gc->chip_types[1].chip.irq_unmask = irq_gc_mask_set_bit, 508 - gc->chip_types[1].chip.irq_set_type = gpio_set_irq_type, 509 - gc->chip_types[1].chip.irq_set_wake = gpio_set_irq_wake, 510 - gc->chip_types[1].chip.flags = IRQCHIP_MASK_ON_SUSPEND, 504 + gc->chip_types[1].chip.irq_startup = gpio_startup_irq; 505 + gc->chip_types[1].chip.irq_ack = irq_gc_ack_clr_bit; 506 + gc->chip_types[1].chip.irq_mask = irq_gc_mask_clr_bit; 507 + gc->chip_types[1].chip.irq_unmask = irq_gc_mask_set_bit; 508 + gc->chip_types[1].chip.irq_set_type = gpio_set_irq_type; 509 + gc->chip_types[1].chip.irq_set_wake = gpio_set_irq_wake; 510 + gc->chip_types[1].chip.flags = IRQCHIP_MASK_ON_SUSPEND; 511 511 512 512 /* Setup chained handler for this GPIO bank */ 513 513 irq_set_handler_data(bank->irq, bank);
+220
drivers/gpio/gpio-zevio.c
··· 1 + /* 2 + * GPIO controller in LSI ZEVIO SoCs. 3 + * 4 + * Author: Fabian Vogt <fabian@ritter-vogt.de> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/spinlock.h> 12 + #include <linux/errno.h> 13 + #include <linux/module.h> 14 + #include <linux/bitops.h> 15 + #include <linux/io.h> 16 + #include <linux/of_device.h> 17 + #include <linux/of_gpio.h> 18 + #include <linux/slab.h> 19 + #include <linux/gpio.h> 20 + 21 + /* 22 + * Memory layout: 23 + * This chip has four gpio sections, each controls 8 GPIOs. 24 + * Bit 0 in section 0 is GPIO 0, bit 2 in section 1 is GPIO 10. 25 + * Disclaimer: Reverse engineered! 26 + * For more information refer to: 27 + * http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#90000000_-_General_Purpose_I.2FO_.28GPIO.29 28 + * 29 + * 0x00-0x3F: Section 0 30 + * +0x00: Masked interrupt status (read-only) 31 + * +0x04: R: Interrupt status W: Reset interrupt status 32 + * +0x08: R: Interrupt mask W: Mask interrupt 33 + * +0x0C: W: Unmask interrupt (write-only) 34 + * +0x10: Direction: I/O=1/0 35 + * +0x14: Output 36 + * +0x18: Input (read-only) 37 + * +0x20: R: Level interrupt W: Set as level interrupt 38 + * 0x40-0x7F: Section 1 39 + * 0x80-0xBF: Section 2 40 + * 0xC0-0xFF: Section 3 41 + */ 42 + 43 + #define ZEVIO_GPIO_SECTION_SIZE 0x40 44 + 45 + /* Offsets to various registers */ 46 + #define ZEVIO_GPIO_INT_MASKED_STATUS 0x00 47 + #define ZEVIO_GPIO_INT_STATUS 0x04 48 + #define ZEVIO_GPIO_INT_UNMASK 0x08 49 + #define ZEVIO_GPIO_INT_MASK 0x0C 50 + #define ZEVIO_GPIO_DIRECTION 0x10 51 + #define ZEVIO_GPIO_OUTPUT 0x14 52 + #define ZEVIO_GPIO_INPUT 0x18 53 + #define ZEVIO_GPIO_INT_STICKY 0x20 54 + 55 + #define to_zevio_gpio(chip) container_of(to_of_mm_gpio_chip(chip), \ 56 + struct zevio_gpio, chip) 57 + 58 + /* Bit number of GPIO in its section */ 59 + #define ZEVIO_GPIO_BIT(gpio) (gpio&7) 60 + 61 + struct zevio_gpio { 62 + spinlock_t lock; 63 + struct of_mm_gpio_chip chip; 64 + }; 65 + 66 + static inline u32 zevio_gpio_port_get(struct zevio_gpio *c, unsigned pin, 67 + unsigned port_offset) 68 + { 69 + unsigned section_offset = ((pin >> 3) & 3)*ZEVIO_GPIO_SECTION_SIZE; 70 + return readl(IOMEM(c->chip.regs + section_offset + port_offset)); 71 + } 72 + 73 + static inline void zevio_gpio_port_set(struct zevio_gpio *c, unsigned pin, 74 + unsigned port_offset, u32 val) 75 + { 76 + unsigned section_offset = ((pin >> 3) & 3)*ZEVIO_GPIO_SECTION_SIZE; 77 + writel(val, IOMEM(c->chip.regs + section_offset + port_offset)); 78 + } 79 + 80 + /* Functions for struct gpio_chip */ 81 + static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin) 82 + { 83 + struct zevio_gpio *controller = to_zevio_gpio(chip); 84 + 85 + /* Only reading allowed, so no spinlock needed */ 86 + u32 val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT); 87 + 88 + return (val >> ZEVIO_GPIO_BIT(pin)) & 0x1; 89 + } 90 + 91 + static void zevio_gpio_set(struct gpio_chip *chip, unsigned pin, int value) 92 + { 93 + struct zevio_gpio *controller = to_zevio_gpio(chip); 94 + u32 val; 95 + 96 + spin_lock(&controller->lock); 97 + val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_OUTPUT); 98 + if (value) 99 + val |= BIT(ZEVIO_GPIO_BIT(pin)); 100 + else 101 + val &= ~BIT(ZEVIO_GPIO_BIT(pin)); 102 + 103 + zevio_gpio_port_set(controller, pin, ZEVIO_GPIO_OUTPUT, val); 104 + spin_unlock(&controller->lock); 105 + } 106 + 107 + static int zevio_gpio_direction_input(struct gpio_chip *chip, unsigned pin) 108 + { 109 + struct zevio_gpio *controller = to_zevio_gpio(chip); 110 + u32 val; 111 + 112 + spin_lock(&controller->lock); 113 + 114 + val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_DIRECTION); 115 + val |= BIT(ZEVIO_GPIO_BIT(pin)); 116 + zevio_gpio_port_set(controller, pin, ZEVIO_GPIO_DIRECTION, val); 117 + 118 + spin_unlock(&controller->lock); 119 + 120 + return 0; 121 + } 122 + 123 + static int zevio_gpio_direction_output(struct gpio_chip *chip, 124 + unsigned pin, int value) 125 + { 126 + struct zevio_gpio *controller = to_zevio_gpio(chip); 127 + u32 val; 128 + 129 + spin_lock(&controller->lock); 130 + val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_OUTPUT); 131 + if (value) 132 + val |= BIT(ZEVIO_GPIO_BIT(pin)); 133 + else 134 + val &= ~BIT(ZEVIO_GPIO_BIT(pin)); 135 + 136 + zevio_gpio_port_set(controller, pin, ZEVIO_GPIO_OUTPUT, val); 137 + val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_DIRECTION); 138 + val &= ~BIT(ZEVIO_GPIO_BIT(pin)); 139 + zevio_gpio_port_set(controller, pin, ZEVIO_GPIO_DIRECTION, val); 140 + 141 + spin_unlock(&controller->lock); 142 + 143 + return 0; 144 + } 145 + 146 + static int zevio_gpio_to_irq(struct gpio_chip *chip, unsigned pin) 147 + { 148 + /* 149 + * TODO: Implement IRQs. 150 + * Not implemented yet due to weird lockups 151 + */ 152 + 153 + return -ENXIO; 154 + } 155 + 156 + static struct gpio_chip zevio_gpio_chip = { 157 + .direction_input = zevio_gpio_direction_input, 158 + .direction_output = zevio_gpio_direction_output, 159 + .set = zevio_gpio_set, 160 + .get = zevio_gpio_get, 161 + .to_irq = zevio_gpio_to_irq, 162 + .base = 0, 163 + .owner = THIS_MODULE, 164 + .ngpio = 32, 165 + .of_gpio_n_cells = 2, 166 + }; 167 + 168 + /* Initialization */ 169 + static int zevio_gpio_probe(struct platform_device *pdev) 170 + { 171 + struct zevio_gpio *controller; 172 + int status, i; 173 + 174 + controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL); 175 + if (!controller) { 176 + dev_err(&pdev->dev, "not enough free memory\n"); 177 + return -ENOMEM; 178 + } 179 + 180 + /* Copy our reference */ 181 + controller->chip.gc = zevio_gpio_chip; 182 + controller->chip.gc.dev = &pdev->dev; 183 + 184 + status = of_mm_gpiochip_add(pdev->dev.of_node, &(controller->chip)); 185 + if (status) { 186 + dev_err(&pdev->dev, "failed to add gpiochip: %d\n", status); 187 + return status; 188 + } 189 + 190 + spin_lock_init(&controller->lock); 191 + 192 + /* Disable interrupts, they only cause errors */ 193 + for (i = 0; i < controller->chip.gc.ngpio; i += 8) 194 + zevio_gpio_port_set(controller, i, ZEVIO_GPIO_INT_MASK, 0xFF); 195 + 196 + dev_dbg(controller->chip.gc.dev, "ZEVIO GPIO controller set up!\n"); 197 + 198 + return 0; 199 + } 200 + 201 + static struct of_device_id zevio_gpio_of_match[] = { 202 + { .compatible = "lsi,zevio-gpio", }, 203 + { }, 204 + }; 205 + 206 + MODULE_DEVICE_TABLE(of, zevio_gpio_of_match); 207 + 208 + static struct platform_driver zevio_gpio_driver = { 209 + .driver = { 210 + .name = "gpio-zevio", 211 + .owner = THIS_MODULE, 212 + .of_match_table = of_match_ptr(zevio_gpio_of_match), 213 + }, 214 + .probe = zevio_gpio_probe, 215 + }; 216 + module_platform_driver(zevio_gpio_driver); 217 + 218 + MODULE_LICENSE("GPL"); 219 + MODULE_AUTHOR("Fabian Vogt <fabian@ritter-vogt.de>"); 220 + MODULE_DESCRIPTION("LSI ZEVIO SoC GPIO driver");
+356 -128
drivers/gpio/gpiolib-acpi.c
··· 16 16 #include <linux/export.h> 17 17 #include <linux/acpi.h> 18 18 #include <linux/interrupt.h> 19 + #include <linux/mutex.h> 19 20 20 21 #include "gpiolib.h" 21 22 22 - struct acpi_gpio_evt_pin { 23 + struct acpi_gpio_event { 23 24 struct list_head node; 24 - acpi_handle *evt_handle; 25 + acpi_handle handle; 25 26 unsigned int pin; 26 27 unsigned int irq; 28 + }; 29 + 30 + struct acpi_gpio_connection { 31 + struct list_head node; 32 + struct gpio_desc *desc; 33 + }; 34 + 35 + struct acpi_gpio_chip { 36 + /* 37 + * ACPICA requires that the first field of the context parameter 38 + * passed to acpi_install_address_space_handler() is large enough 39 + * to hold struct acpi_connection_info. 40 + */ 41 + struct acpi_connection_info conn_info; 42 + struct list_head conns; 43 + struct mutex conn_lock; 44 + struct gpio_chip *chip; 45 + struct list_head events; 27 46 }; 28 47 29 48 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) ··· 79 60 if (pin < 0 || pin > chip->ngpio) 80 61 return ERR_PTR(-EINVAL); 81 62 82 - return gpio_to_desc(chip->base + pin); 63 + return gpiochip_get_desc(chip, pin); 83 64 } 84 65 85 66 static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) 86 67 { 87 - acpi_handle handle = data; 68 + struct acpi_gpio_event *event = data; 88 69 89 - acpi_evaluate_object(handle, NULL, NULL, NULL); 70 + acpi_evaluate_object(event->handle, NULL, NULL, NULL); 90 71 91 72 return IRQ_HANDLED; 92 73 } 93 74 94 75 static irqreturn_t acpi_gpio_irq_handler_evt(int irq, void *data) 95 76 { 96 - struct acpi_gpio_evt_pin *evt_pin = data; 77 + struct acpi_gpio_event *event = data; 97 78 98 - acpi_execute_simple_method(evt_pin->evt_handle, NULL, evt_pin->pin); 79 + acpi_execute_simple_method(event->handle, NULL, event->pin); 99 80 100 81 return IRQ_HANDLED; 101 82 } 102 83 103 - static void acpi_gpio_evt_dh(acpi_handle handle, void *data) 84 + static void acpi_gpio_chip_dh(acpi_handle handle, void *data) 104 85 { 105 86 /* The address of this function is used as a key. */ 106 87 } 107 88 89 + static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, 90 + void *context) 91 + { 92 + struct acpi_gpio_chip *acpi_gpio = context; 93 + struct gpio_chip *chip = acpi_gpio->chip; 94 + struct acpi_resource_gpio *agpio; 95 + acpi_handle handle, evt_handle; 96 + struct acpi_gpio_event *event; 97 + irq_handler_t handler = NULL; 98 + struct gpio_desc *desc; 99 + unsigned long irqflags; 100 + int ret, pin, irq; 101 + 102 + if (ares->type != ACPI_RESOURCE_TYPE_GPIO) 103 + return AE_OK; 104 + 105 + agpio = &ares->data.gpio; 106 + if (agpio->connection_type != ACPI_RESOURCE_GPIO_TYPE_INT) 107 + return AE_OK; 108 + 109 + handle = ACPI_HANDLE(chip->dev); 110 + pin = agpio->pin_table[0]; 111 + 112 + if (pin <= 255) { 113 + char ev_name[5]; 114 + sprintf(ev_name, "_%c%02X", 115 + agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', 116 + pin); 117 + if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name, &evt_handle))) 118 + handler = acpi_gpio_irq_handler; 119 + } 120 + if (!handler) { 121 + if (ACPI_SUCCESS(acpi_get_handle(handle, "_EVT", &evt_handle))) 122 + handler = acpi_gpio_irq_handler_evt; 123 + } 124 + if (!handler) 125 + return AE_BAD_PARAMETER; 126 + 127 + desc = gpiochip_get_desc(chip, pin); 128 + if (IS_ERR(desc)) { 129 + dev_err(chip->dev, "Failed to get GPIO descriptor\n"); 130 + return AE_ERROR; 131 + } 132 + 133 + ret = gpiochip_request_own_desc(desc, "ACPI:Event"); 134 + if (ret) { 135 + dev_err(chip->dev, "Failed to request GPIO\n"); 136 + return AE_ERROR; 137 + } 138 + 139 + gpiod_direction_input(desc); 140 + 141 + ret = gpiod_lock_as_irq(desc); 142 + if (ret) { 143 + dev_err(chip->dev, "Failed to lock GPIO as interrupt\n"); 144 + goto fail_free_desc; 145 + } 146 + 147 + irq = gpiod_to_irq(desc); 148 + if (irq < 0) { 149 + dev_err(chip->dev, "Failed to translate GPIO to IRQ\n"); 150 + goto fail_unlock_irq; 151 + } 152 + 153 + irqflags = IRQF_ONESHOT; 154 + if (agpio->triggering == ACPI_LEVEL_SENSITIVE) { 155 + if (agpio->polarity == ACPI_ACTIVE_HIGH) 156 + irqflags |= IRQF_TRIGGER_HIGH; 157 + else 158 + irqflags |= IRQF_TRIGGER_LOW; 159 + } else { 160 + switch (agpio->polarity) { 161 + case ACPI_ACTIVE_HIGH: 162 + irqflags |= IRQF_TRIGGER_RISING; 163 + break; 164 + case ACPI_ACTIVE_LOW: 165 + irqflags |= IRQF_TRIGGER_FALLING; 166 + break; 167 + default: 168 + irqflags |= IRQF_TRIGGER_RISING | 169 + IRQF_TRIGGER_FALLING; 170 + break; 171 + } 172 + } 173 + 174 + event = kzalloc(sizeof(*event), GFP_KERNEL); 175 + if (!event) 176 + goto fail_unlock_irq; 177 + 178 + event->handle = evt_handle; 179 + event->irq = irq; 180 + event->pin = pin; 181 + 182 + ret = request_threaded_irq(event->irq, NULL, handler, irqflags, 183 + "ACPI:Event", event); 184 + if (ret) { 185 + dev_err(chip->dev, "Failed to setup interrupt handler for %d\n", 186 + event->irq); 187 + goto fail_free_event; 188 + } 189 + 190 + list_add_tail(&event->node, &acpi_gpio->events); 191 + return AE_OK; 192 + 193 + fail_free_event: 194 + kfree(event); 195 + fail_unlock_irq: 196 + gpiod_unlock_as_irq(desc); 197 + fail_free_desc: 198 + gpiochip_free_own_desc(desc); 199 + 200 + return AE_ERROR; 201 + } 202 + 108 203 /** 109 204 * acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events 110 - * @chip: gpio chip 205 + * @acpi_gpio: ACPI GPIO chip 111 206 * 112 207 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are 113 208 * handled by ACPI event methods which need to be called from the GPIO ··· 229 96 * gpio pins have acpi event methods and assigns interrupt handlers that calls 230 97 * the acpi event methods for those pins. 231 98 */ 232 - static void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) 99 + static void acpi_gpiochip_request_interrupts(struct acpi_gpio_chip *acpi_gpio) 233 100 { 234 - struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL}; 235 - struct acpi_resource *res; 236 - acpi_handle handle, evt_handle; 237 - struct list_head *evt_pins = NULL; 238 - acpi_status status; 239 - unsigned int pin; 240 - int irq, ret; 241 - char ev_name[5]; 101 + struct gpio_chip *chip = acpi_gpio->chip; 242 102 243 103 if (!chip->dev || !chip->to_irq) 244 104 return; 245 105 246 - handle = ACPI_HANDLE(chip->dev); 247 - if (!handle) 248 - return; 249 - 250 - status = acpi_get_event_resources(handle, &buf); 251 - if (ACPI_FAILURE(status)) 252 - return; 253 - 254 - status = acpi_get_handle(handle, "_EVT", &evt_handle); 255 - if (ACPI_SUCCESS(status)) { 256 - evt_pins = kzalloc(sizeof(*evt_pins), GFP_KERNEL); 257 - if (evt_pins) { 258 - INIT_LIST_HEAD(evt_pins); 259 - status = acpi_attach_data(handle, acpi_gpio_evt_dh, 260 - evt_pins); 261 - if (ACPI_FAILURE(status)) { 262 - kfree(evt_pins); 263 - evt_pins = NULL; 264 - } 265 - } 266 - } 267 - 268 - /* 269 - * If a GPIO interrupt has an ACPI event handler method, or _EVT is 270 - * present, set up an interrupt handler that calls the ACPI event 271 - * handler. 272 - */ 273 - for (res = buf.pointer; 274 - res && (res->type != ACPI_RESOURCE_TYPE_END_TAG); 275 - res = ACPI_NEXT_RESOURCE(res)) { 276 - irq_handler_t handler = NULL; 277 - void *data; 278 - 279 - if (res->type != ACPI_RESOURCE_TYPE_GPIO || 280 - res->data.gpio.connection_type != 281 - ACPI_RESOURCE_GPIO_TYPE_INT) 282 - continue; 283 - 284 - pin = res->data.gpio.pin_table[0]; 285 - if (pin > chip->ngpio) 286 - continue; 287 - 288 - irq = chip->to_irq(chip, pin); 289 - if (irq < 0) 290 - continue; 291 - 292 - if (pin <= 255) { 293 - acpi_handle ev_handle; 294 - 295 - sprintf(ev_name, "_%c%02X", 296 - res->data.gpio.triggering ? 'E' : 'L', pin); 297 - status = acpi_get_handle(handle, ev_name, &ev_handle); 298 - if (ACPI_SUCCESS(status)) { 299 - handler = acpi_gpio_irq_handler; 300 - data = ev_handle; 301 - } 302 - } 303 - if (!handler && evt_pins) { 304 - struct acpi_gpio_evt_pin *evt_pin; 305 - 306 - evt_pin = kzalloc(sizeof(*evt_pin), GFP_KERNEL); 307 - if (!evt_pin) 308 - continue; 309 - 310 - list_add_tail(&evt_pin->node, evt_pins); 311 - evt_pin->evt_handle = evt_handle; 312 - evt_pin->pin = pin; 313 - evt_pin->irq = irq; 314 - handler = acpi_gpio_irq_handler_evt; 315 - data = evt_pin; 316 - } 317 - if (!handler) 318 - continue; 319 - 320 - /* Assume BIOS sets the triggering, so no flags */ 321 - ret = devm_request_threaded_irq(chip->dev, irq, NULL, handler, 322 - 0, "GPIO-signaled-ACPI-event", 323 - data); 324 - if (ret) 325 - dev_err(chip->dev, 326 - "Failed to request IRQ %d ACPI event handler\n", 327 - irq); 328 - } 106 + INIT_LIST_HEAD(&acpi_gpio->events); 107 + acpi_walk_resources(ACPI_HANDLE(chip->dev), "_AEI", 108 + acpi_gpiochip_request_interrupt, acpi_gpio); 329 109 } 330 110 331 111 /** 332 - * acpi_gpiochip_free_interrupts() - Free GPIO _EVT ACPI event interrupts. 333 - * @chip: gpio chip 112 + * acpi_gpiochip_free_interrupts() - Free GPIO ACPI event interrupts. 113 + * @acpi_gpio: ACPI GPIO chip 334 114 * 335 - * Free interrupts associated with the _EVT method for the given GPIO chip. 336 - * 337 - * The remaining ACPI event interrupts associated with the chip are freed 338 - * automatically. 115 + * Free interrupts associated with GPIO ACPI event method for the given 116 + * GPIO chip. 339 117 */ 340 - static void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) 118 + static void acpi_gpiochip_free_interrupts(struct acpi_gpio_chip *acpi_gpio) 341 119 { 342 - acpi_handle handle; 343 - acpi_status status; 344 - struct list_head *evt_pins; 345 - struct acpi_gpio_evt_pin *evt_pin, *ep; 120 + struct acpi_gpio_event *event, *ep; 121 + struct gpio_chip *chip = acpi_gpio->chip; 346 122 347 123 if (!chip->dev || !chip->to_irq) 348 124 return; 349 125 350 - handle = ACPI_HANDLE(chip->dev); 351 - if (!handle) 352 - return; 126 + list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) { 127 + struct gpio_desc *desc; 353 128 354 - status = acpi_get_data(handle, acpi_gpio_evt_dh, (void **)&evt_pins); 355 - if (ACPI_FAILURE(status)) 356 - return; 357 - 358 - list_for_each_entry_safe_reverse(evt_pin, ep, evt_pins, node) { 359 - devm_free_irq(chip->dev, evt_pin->irq, evt_pin); 360 - list_del(&evt_pin->node); 361 - kfree(evt_pin); 129 + free_irq(event->irq, event); 130 + desc = gpiochip_get_desc(chip, event->pin); 131 + if (WARN_ON(IS_ERR(desc))) 132 + continue; 133 + gpiod_unlock_as_irq(desc); 134 + gpiochip_free_own_desc(desc); 135 + list_del(&event->node); 136 + kfree(event); 362 137 } 363 - 364 - acpi_detach_data(handle, acpi_gpio_evt_dh); 365 - kfree(evt_pins); 366 138 } 367 139 368 140 struct acpi_gpio_lookup { ··· 348 310 return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT); 349 311 } 350 312 313 + static acpi_status 314 + acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address, 315 + u32 bits, u64 *value, void *handler_context, 316 + void *region_context) 317 + { 318 + struct acpi_gpio_chip *achip = region_context; 319 + struct gpio_chip *chip = achip->chip; 320 + struct acpi_resource_gpio *agpio; 321 + struct acpi_resource *ares; 322 + acpi_status status; 323 + bool pull_up; 324 + int i; 325 + 326 + status = acpi_buffer_to_resource(achip->conn_info.connection, 327 + achip->conn_info.length, &ares); 328 + if (ACPI_FAILURE(status)) 329 + return status; 330 + 331 + if (WARN_ON(ares->type != ACPI_RESOURCE_TYPE_GPIO)) { 332 + ACPI_FREE(ares); 333 + return AE_BAD_PARAMETER; 334 + } 335 + 336 + agpio = &ares->data.gpio; 337 + pull_up = agpio->pin_config == ACPI_PIN_CONFIG_PULLUP; 338 + 339 + if (WARN_ON(agpio->io_restriction == ACPI_IO_RESTRICT_INPUT && 340 + function == ACPI_WRITE)) { 341 + ACPI_FREE(ares); 342 + return AE_BAD_PARAMETER; 343 + } 344 + 345 + for (i = 0; i < agpio->pin_table_length; i++) { 346 + unsigned pin = agpio->pin_table[i]; 347 + struct acpi_gpio_connection *conn; 348 + struct gpio_desc *desc; 349 + bool found; 350 + 351 + desc = gpiochip_get_desc(chip, pin); 352 + if (IS_ERR(desc)) { 353 + status = AE_ERROR; 354 + goto out; 355 + } 356 + 357 + mutex_lock(&achip->conn_lock); 358 + 359 + found = false; 360 + list_for_each_entry(conn, &achip->conns, node) { 361 + if (conn->desc == desc) { 362 + found = true; 363 + break; 364 + } 365 + } 366 + if (!found) { 367 + int ret; 368 + 369 + ret = gpiochip_request_own_desc(desc, "ACPI:OpRegion"); 370 + if (ret) { 371 + status = AE_ERROR; 372 + mutex_unlock(&achip->conn_lock); 373 + goto out; 374 + } 375 + 376 + switch (agpio->io_restriction) { 377 + case ACPI_IO_RESTRICT_INPUT: 378 + gpiod_direction_input(desc); 379 + break; 380 + case ACPI_IO_RESTRICT_OUTPUT: 381 + /* 382 + * ACPI GPIO resources don't contain an 383 + * initial value for the GPIO. Therefore we 384 + * deduce that value from the pull field 385 + * instead. If the pin is pulled up we 386 + * assume default to be high, otherwise 387 + * low. 388 + */ 389 + gpiod_direction_output(desc, pull_up); 390 + break; 391 + default: 392 + /* 393 + * Assume that the BIOS has configured the 394 + * direction and pull accordingly. 395 + */ 396 + break; 397 + } 398 + 399 + conn = kzalloc(sizeof(*conn), GFP_KERNEL); 400 + if (!conn) { 401 + status = AE_NO_MEMORY; 402 + gpiochip_free_own_desc(desc); 403 + mutex_unlock(&achip->conn_lock); 404 + goto out; 405 + } 406 + 407 + conn->desc = desc; 408 + list_add_tail(&conn->node, &achip->conns); 409 + } 410 + 411 + mutex_unlock(&achip->conn_lock); 412 + 413 + if (function == ACPI_WRITE) 414 + gpiod_set_raw_value(desc, !!((1 << i) & *value)); 415 + else 416 + *value |= gpiod_get_raw_value(desc) << i; 417 + } 418 + 419 + out: 420 + ACPI_FREE(ares); 421 + return status; 422 + } 423 + 424 + static void acpi_gpiochip_request_regions(struct acpi_gpio_chip *achip) 425 + { 426 + struct gpio_chip *chip = achip->chip; 427 + acpi_handle handle = ACPI_HANDLE(chip->dev); 428 + acpi_status status; 429 + 430 + INIT_LIST_HEAD(&achip->conns); 431 + mutex_init(&achip->conn_lock); 432 + status = acpi_install_address_space_handler(handle, ACPI_ADR_SPACE_GPIO, 433 + acpi_gpio_adr_space_handler, 434 + NULL, achip); 435 + if (ACPI_FAILURE(status)) 436 + dev_err(chip->dev, "Failed to install GPIO OpRegion handler\n"); 437 + } 438 + 439 + static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip) 440 + { 441 + struct gpio_chip *chip = achip->chip; 442 + acpi_handle handle = ACPI_HANDLE(chip->dev); 443 + struct acpi_gpio_connection *conn, *tmp; 444 + acpi_status status; 445 + 446 + status = acpi_remove_address_space_handler(handle, ACPI_ADR_SPACE_GPIO, 447 + acpi_gpio_adr_space_handler); 448 + if (ACPI_FAILURE(status)) { 449 + dev_err(chip->dev, "Failed to remove GPIO OpRegion handler\n"); 450 + return; 451 + } 452 + 453 + list_for_each_entry_safe_reverse(conn, tmp, &achip->conns, node) { 454 + gpiochip_free_own_desc(conn->desc); 455 + list_del(&conn->node); 456 + kfree(conn); 457 + } 458 + } 459 + 351 460 void acpi_gpiochip_add(struct gpio_chip *chip) 352 461 { 353 - acpi_gpiochip_request_interrupts(chip); 462 + struct acpi_gpio_chip *acpi_gpio; 463 + acpi_handle handle; 464 + acpi_status status; 465 + 466 + handle = ACPI_HANDLE(chip->dev); 467 + if (!handle) 468 + return; 469 + 470 + acpi_gpio = kzalloc(sizeof(*acpi_gpio), GFP_KERNEL); 471 + if (!acpi_gpio) { 472 + dev_err(chip->dev, 473 + "Failed to allocate memory for ACPI GPIO chip\n"); 474 + return; 475 + } 476 + 477 + acpi_gpio->chip = chip; 478 + 479 + status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio); 480 + if (ACPI_FAILURE(status)) { 481 + dev_err(chip->dev, "Failed to attach ACPI GPIO chip\n"); 482 + kfree(acpi_gpio); 483 + return; 484 + } 485 + 486 + acpi_gpiochip_request_interrupts(acpi_gpio); 487 + acpi_gpiochip_request_regions(acpi_gpio); 354 488 } 355 489 356 490 void acpi_gpiochip_remove(struct gpio_chip *chip) 357 491 { 358 - acpi_gpiochip_free_interrupts(chip); 492 + struct acpi_gpio_chip *acpi_gpio; 493 + acpi_handle handle; 494 + acpi_status status; 495 + 496 + handle = ACPI_HANDLE(chip->dev); 497 + if (!handle) 498 + return; 499 + 500 + status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); 501 + if (ACPI_FAILURE(status)) { 502 + dev_warn(chip->dev, "Failed to retrieve ACPI GPIO chip\n"); 503 + return; 504 + } 505 + 506 + acpi_gpiochip_free_regions(acpi_gpio); 507 + acpi_gpiochip_free_interrupts(acpi_gpio); 508 + 509 + acpi_detach_data(handle, acpi_gpio_chip_dh); 510 + kfree(acpi_gpio); 359 511 }
+2 -1
drivers/gpio/gpiolib-of.c
··· 12 12 */ 13 13 14 14 #include <linux/device.h> 15 + #include <linux/err.h> 15 16 #include <linux/errno.h> 16 17 #include <linux/module.h> 17 18 #include <linux/io.h> ··· 91 90 92 91 of_node_put(gg_data.gpiospec.np); 93 92 pr_debug("%s exited with status %d\n", __func__, 94 - PTR_RET(gg_data.out_gpio)); 93 + PTR_ERR_OR_ZERO(gg_data.out_gpio)); 95 94 return gg_data.out_gpio; 96 95 } 97 96 EXPORT_SYMBOL(of_get_named_gpiod_flags);
+352 -65
drivers/gpio/gpiolib.c
··· 164 164 EXPORT_SYMBOL_GPL(gpio_to_desc); 165 165 166 166 /** 167 - * Convert an offset on a certain chip to a corresponding descriptor 167 + * Get the GPIO descriptor corresponding to the given hw number for this chip. 168 168 */ 169 - static struct gpio_desc *gpiochip_offset_to_desc(struct gpio_chip *chip, 170 - unsigned int offset) 169 + struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, 170 + u16 hwnum) 171 171 { 172 - if (offset >= chip->ngpio) 172 + if (hwnum >= chip->ngpio) 173 173 return ERR_PTR(-EINVAL); 174 174 175 - return &chip->desc[offset]; 175 + return &chip->desc[hwnum]; 176 176 } 177 + EXPORT_SYMBOL_GPL(gpiochip_get_desc); 177 178 178 179 /** 179 180 * Convert a GPIO descriptor to the integer namespace. ··· 351 350 if (!test_bit(FLAG_EXPORT, &desc->flags)) 352 351 status = -EIO; 353 352 else if (sysfs_streq(buf, "high")) 354 - status = gpiod_direction_output(desc, 1); 353 + status = gpiod_direction_output_raw(desc, 1); 355 354 else if (sysfs_streq(buf, "out") || sysfs_streq(buf, "low")) 356 - status = gpiod_direction_output(desc, 0); 355 + status = gpiod_direction_output_raw(desc, 0); 357 356 else if (sysfs_streq(buf, "in")) 358 357 status = gpiod_direction_input(desc); 359 358 else ··· 1254 1253 } 1255 1254 EXPORT_SYMBOL_GPL(gpiochip_add); 1256 1255 1256 + /* Forward-declaration */ 1257 + static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); 1258 + 1257 1259 /** 1258 1260 * gpiochip_remove() - unregister a gpio_chip 1259 1261 * @chip: the chip to unregister ··· 1269 1265 int status = 0; 1270 1266 unsigned id; 1271 1267 1268 + acpi_gpiochip_remove(chip); 1269 + 1272 1270 spin_lock_irqsave(&gpio_lock, flags); 1273 1271 1272 + gpiochip_irqchip_remove(chip); 1274 1273 gpiochip_remove_pin_ranges(chip); 1275 1274 of_gpiochip_remove(chip); 1276 - acpi_gpiochip_remove(chip); 1277 1275 1278 1276 for (id = 0; id < chip->ngpio; id++) { 1279 1277 if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) { ··· 1342 1336 { 1343 1337 return gpiochip_find((void *)name, gpiochip_match_name); 1344 1338 } 1339 + 1340 + #ifdef CONFIG_GPIOLIB_IRQCHIP 1341 + 1342 + /* 1343 + * The following is irqchip helper code for gpiochips. 1344 + */ 1345 + 1346 + /** 1347 + * gpiochip_add_chained_irqchip() - adds a chained irqchip to a gpiochip 1348 + * @gpiochip: the gpiochip to add the irqchip to 1349 + * @irqchip: the irqchip to add to the gpiochip 1350 + * @parent_irq: the irq number corresponding to the parent IRQ for this 1351 + * chained irqchip 1352 + * @parent_handler: the parent interrupt handler for the accumulated IRQ 1353 + * coming out of the gpiochip 1354 + */ 1355 + void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 1356 + struct irq_chip *irqchip, 1357 + int parent_irq, 1358 + irq_flow_handler_t parent_handler) 1359 + { 1360 + irq_set_chained_handler(parent_irq, parent_handler); 1361 + /* 1362 + * The parent irqchip is already using the chip_data for this 1363 + * irqchip, so our callbacks simply use the handler_data. 1364 + */ 1365 + irq_set_handler_data(parent_irq, gpiochip); 1366 + } 1367 + EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip); 1368 + 1369 + /** 1370 + * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip 1371 + * @d: the irqdomain used by this irqchip 1372 + * @irq: the global irq number used by this GPIO irqchip irq 1373 + * @hwirq: the local IRQ/GPIO line offset on this gpiochip 1374 + * 1375 + * This function will set up the mapping for a certain IRQ line on a 1376 + * gpiochip by assigning the gpiochip as chip data, and using the irqchip 1377 + * stored inside the gpiochip. 1378 + */ 1379 + static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 1380 + irq_hw_number_t hwirq) 1381 + { 1382 + struct gpio_chip *chip = d->host_data; 1383 + 1384 + irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); 1385 + irq_set_chip_data(irq, chip); 1386 + #ifdef CONFIG_ARM 1387 + set_irq_flags(irq, IRQF_VALID); 1388 + #else 1389 + irq_set_noprobe(irq); 1390 + #endif 1391 + irq_set_irq_type(irq, chip->irq_default_type); 1392 + 1393 + return 0; 1394 + } 1395 + 1396 + static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) 1397 + { 1398 + #ifdef CONFIG_ARM 1399 + set_irq_flags(irq, 0); 1400 + #endif 1401 + irq_set_chip_and_handler(irq, NULL, NULL); 1402 + irq_set_chip_data(irq, NULL); 1403 + } 1404 + 1405 + static const struct irq_domain_ops gpiochip_domain_ops = { 1406 + .map = gpiochip_irq_map, 1407 + .unmap = gpiochip_irq_unmap, 1408 + /* Virtually all GPIO irqchips are twocell:ed */ 1409 + .xlate = irq_domain_xlate_twocell, 1410 + }; 1411 + 1412 + static int gpiochip_irq_reqres(struct irq_data *d) 1413 + { 1414 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 1415 + 1416 + if (gpio_lock_as_irq(chip, d->hwirq)) { 1417 + chip_err(chip, 1418 + "unable to lock HW IRQ %lu for IRQ\n", 1419 + d->hwirq); 1420 + return -EINVAL; 1421 + } 1422 + return 0; 1423 + } 1424 + 1425 + static void gpiochip_irq_relres(struct irq_data *d) 1426 + { 1427 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 1428 + 1429 + gpio_unlock_as_irq(chip, d->hwirq); 1430 + } 1431 + 1432 + static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) 1433 + { 1434 + return irq_find_mapping(chip->irqdomain, offset); 1435 + } 1436 + 1437 + /** 1438 + * gpiochip_irqchip_remove() - removes an irqchip added to a gpiochip 1439 + * @gpiochip: the gpiochip to remove the irqchip from 1440 + * 1441 + * This is called only from gpiochip_remove() 1442 + */ 1443 + static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) 1444 + { 1445 + unsigned int offset; 1446 + 1447 + /* Remove all IRQ mappings and delete the domain */ 1448 + if (gpiochip->irqdomain) { 1449 + for (offset = 0; offset < gpiochip->ngpio; offset++) 1450 + irq_dispose_mapping(gpiochip->irq_base + offset); 1451 + irq_domain_remove(gpiochip->irqdomain); 1452 + } 1453 + 1454 + if (gpiochip->irqchip) { 1455 + gpiochip->irqchip->irq_request_resources = NULL; 1456 + gpiochip->irqchip->irq_release_resources = NULL; 1457 + gpiochip->irqchip = NULL; 1458 + } 1459 + } 1460 + 1461 + /** 1462 + * gpiochip_irqchip_add() - adds an irqchip to a gpiochip 1463 + * @gpiochip: the gpiochip to add the irqchip to 1464 + * @irqchip: the irqchip to add to the gpiochip 1465 + * @first_irq: if not dynamically assigned, the base (first) IRQ to 1466 + * allocate gpiochip irqs from 1467 + * @handler: the irq handler to use (often a predefined irq core function) 1468 + * @type: the default type for IRQs on this irqchip 1469 + * 1470 + * This function closely associates a certain irqchip with a certain 1471 + * gpiochip, providing an irq domain to translate the local IRQs to 1472 + * global irqs in the gpiolib core, and making sure that the gpiochip 1473 + * is passed as chip data to all related functions. Driver callbacks 1474 + * need to use container_of() to get their local state containers back 1475 + * from the gpiochip passed as chip data. An irqdomain will be stored 1476 + * in the gpiochip that shall be used by the driver to handle IRQ number 1477 + * translation. The gpiochip will need to be initialized and registered 1478 + * before calling this function. 1479 + * 1480 + * This function will handle two cell:ed simple IRQs and assumes all 1481 + * the pins on the gpiochip can generate a unique IRQ. Everything else 1482 + * need to be open coded. 1483 + */ 1484 + int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 1485 + struct irq_chip *irqchip, 1486 + unsigned int first_irq, 1487 + irq_flow_handler_t handler, 1488 + unsigned int type) 1489 + { 1490 + struct device_node *of_node; 1491 + unsigned int offset; 1492 + unsigned irq_base = 0; 1493 + 1494 + if (!gpiochip || !irqchip) 1495 + return -EINVAL; 1496 + 1497 + if (!gpiochip->dev) { 1498 + pr_err("missing gpiochip .dev parent pointer\n"); 1499 + return -EINVAL; 1500 + } 1501 + of_node = gpiochip->dev->of_node; 1502 + #ifdef CONFIG_OF_GPIO 1503 + /* 1504 + * If the gpiochip has an assigned OF node this takes precendence 1505 + * FIXME: get rid of this and use gpiochip->dev->of_node everywhere 1506 + */ 1507 + if (gpiochip->of_node) 1508 + of_node = gpiochip->of_node; 1509 + #endif 1510 + gpiochip->irqchip = irqchip; 1511 + gpiochip->irq_handler = handler; 1512 + gpiochip->irq_default_type = type; 1513 + gpiochip->to_irq = gpiochip_to_irq; 1514 + gpiochip->irqdomain = irq_domain_add_simple(of_node, 1515 + gpiochip->ngpio, first_irq, 1516 + &gpiochip_domain_ops, gpiochip); 1517 + if (!gpiochip->irqdomain) { 1518 + gpiochip->irqchip = NULL; 1519 + return -EINVAL; 1520 + } 1521 + irqchip->irq_request_resources = gpiochip_irq_reqres; 1522 + irqchip->irq_release_resources = gpiochip_irq_relres; 1523 + 1524 + /* 1525 + * Prepare the mapping since the irqchip shall be orthogonal to 1526 + * any gpiochip calls. If the first_irq was zero, this is 1527 + * necessary to allocate descriptors for all IRQs. 1528 + */ 1529 + for (offset = 0; offset < gpiochip->ngpio; offset++) { 1530 + irq_base = irq_create_mapping(gpiochip->irqdomain, offset); 1531 + if (offset == 0) 1532 + /* 1533 + * Store the base into the gpiochip to be used when 1534 + * unmapping the irqs. 1535 + */ 1536 + gpiochip->irq_base = irq_base; 1537 + } 1538 + 1539 + return 0; 1540 + } 1541 + EXPORT_SYMBOL_GPL(gpiochip_irqchip_add); 1542 + 1543 + #else /* CONFIG_GPIOLIB_IRQCHIP */ 1544 + 1545 + static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) {} 1546 + 1547 + #endif /* CONFIG_GPIOLIB_IRQCHIP */ 1345 1548 1346 1549 #ifdef CONFIG_PINCTRL 1347 1550 ··· 1672 1457 * on each other, and help provide better diagnostics in debugfs. 1673 1458 * They're called even less than the "set direction" calls. 1674 1459 */ 1675 - static int gpiod_request(struct gpio_desc *desc, const char *label) 1460 + static int __gpiod_request(struct gpio_desc *desc, const char *label) 1676 1461 { 1677 - struct gpio_chip *chip; 1678 - int status = -EPROBE_DEFER; 1462 + struct gpio_chip *chip = desc->chip; 1463 + int status; 1679 1464 unsigned long flags; 1680 1465 1681 - if (!desc) { 1682 - pr_warn("%s: invalid GPIO\n", __func__); 1683 - return -EINVAL; 1684 - } 1685 - 1686 1466 spin_lock_irqsave(&gpio_lock, flags); 1687 - 1688 - chip = desc->chip; 1689 - if (chip == NULL) 1690 - goto done; 1691 - 1692 - if (!try_module_get(chip->owner)) 1693 - goto done; 1694 1467 1695 1468 /* NOTE: gpio_request() can be called in early boot, 1696 1469 * before IRQs are enabled, for non-sleeping (SOC) GPIOs. ··· 1689 1486 status = 0; 1690 1487 } else { 1691 1488 status = -EBUSY; 1692 - module_put(chip->owner); 1693 1489 goto done; 1694 1490 } 1695 1491 ··· 1700 1498 1701 1499 if (status < 0) { 1702 1500 desc_set_label(desc, NULL); 1703 - module_put(chip->owner); 1704 1501 clear_bit(FLAG_REQUESTED, &desc->flags); 1705 1502 goto done; 1706 1503 } ··· 1711 1510 spin_lock_irqsave(&gpio_lock, flags); 1712 1511 } 1713 1512 done: 1513 + spin_unlock_irqrestore(&gpio_lock, flags); 1514 + return status; 1515 + } 1516 + 1517 + static int gpiod_request(struct gpio_desc *desc, const char *label) 1518 + { 1519 + int status = -EPROBE_DEFER; 1520 + struct gpio_chip *chip; 1521 + 1522 + if (!desc) { 1523 + pr_warn("%s: invalid GPIO\n", __func__); 1524 + return -EINVAL; 1525 + } 1526 + 1527 + chip = desc->chip; 1528 + if (!chip) 1529 + goto done; 1530 + 1531 + if (try_module_get(chip->owner)) { 1532 + status = __gpiod_request(desc, label); 1533 + if (status < 0) 1534 + module_put(chip->owner); 1535 + } 1536 + 1537 + done: 1714 1538 if (status) 1715 1539 gpiod_dbg(desc, "%s: status %d\n", __func__, status); 1716 - spin_unlock_irqrestore(&gpio_lock, flags); 1540 + 1717 1541 return status; 1718 1542 } 1719 1543 ··· 1748 1522 } 1749 1523 EXPORT_SYMBOL_GPL(gpio_request); 1750 1524 1751 - static void gpiod_free(struct gpio_desc *desc) 1525 + static bool __gpiod_free(struct gpio_desc *desc) 1752 1526 { 1527 + bool ret = false; 1753 1528 unsigned long flags; 1754 1529 struct gpio_chip *chip; 1755 1530 1756 1531 might_sleep(); 1757 - 1758 - if (!desc) { 1759 - WARN_ON(extra_checks); 1760 - return; 1761 - } 1762 1532 1763 1533 gpiod_unexport(desc); 1764 1534 ··· 1769 1547 spin_lock_irqsave(&gpio_lock, flags); 1770 1548 } 1771 1549 desc_set_label(desc, NULL); 1772 - module_put(desc->chip->owner); 1773 1550 clear_bit(FLAG_ACTIVE_LOW, &desc->flags); 1774 1551 clear_bit(FLAG_REQUESTED, &desc->flags); 1775 1552 clear_bit(FLAG_OPEN_DRAIN, &desc->flags); 1776 1553 clear_bit(FLAG_OPEN_SOURCE, &desc->flags); 1777 - } else 1778 - WARN_ON(extra_checks); 1554 + ret = true; 1555 + } 1779 1556 1780 1557 spin_unlock_irqrestore(&gpio_lock, flags); 1558 + return ret; 1559 + } 1560 + 1561 + static void gpiod_free(struct gpio_desc *desc) 1562 + { 1563 + if (desc && __gpiod_free(desc)) 1564 + module_put(desc->chip->owner); 1565 + else 1566 + WARN_ON(extra_checks); 1781 1567 } 1782 1568 1783 1569 void gpio_free(unsigned gpio) ··· 1820 1590 if (flags & GPIOF_DIR_IN) 1821 1591 err = gpiod_direction_input(desc); 1822 1592 else 1823 - err = gpiod_direction_output(desc, 1593 + err = gpiod_direction_output_raw(desc, 1824 1594 (flags & GPIOF_INIT_HIGH) ? 1 : 0); 1825 1595 1826 1596 if (err) ··· 1907 1677 } 1908 1678 EXPORT_SYMBOL_GPL(gpiochip_is_requested); 1909 1679 1680 + /** 1681 + * gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor 1682 + * @desc: GPIO descriptor to request 1683 + * @label: label for the GPIO 1684 + * 1685 + * Function allows GPIO chip drivers to request and use their own GPIO 1686 + * descriptors via gpiolib API. Difference to gpiod_request() is that this 1687 + * function will not increase reference count of the GPIO chip module. This 1688 + * allows the GPIO chip module to be unloaded as needed (we assume that the 1689 + * GPIO chip driver handles freeing the GPIOs it has requested). 1690 + */ 1691 + int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label) 1692 + { 1693 + if (!desc || !desc->chip) 1694 + return -EINVAL; 1695 + 1696 + return __gpiod_request(desc, label); 1697 + } 1698 + 1699 + /** 1700 + * gpiochip_free_own_desc - Free GPIO requested by the chip driver 1701 + * @desc: GPIO descriptor to free 1702 + * 1703 + * Function frees the given GPIO requested previously with 1704 + * gpiochip_request_own_desc(). 1705 + */ 1706 + void gpiochip_free_own_desc(struct gpio_desc *desc) 1707 + { 1708 + if (desc) 1709 + __gpiod_free(desc); 1710 + } 1910 1711 1911 1712 /* Drivers MUST set GPIO direction before making get/set calls. In 1912 1713 * some cases this is done in early boot, before IRQs are enabled. ··· 2017 1756 } 2018 1757 EXPORT_SYMBOL_GPL(gpiod_direction_input); 2019 1758 2020 - /** 2021 - * gpiod_direction_output - set the GPIO direction to input 2022 - * @desc: GPIO to set to output 2023 - * @value: initial output value of the GPIO 2024 - * 2025 - * Set the direction of the passed GPIO to output, such as gpiod_set_value() can 2026 - * be called safely on it. The initial value of the output must be specified. 2027 - * 2028 - * Return 0 in case of success, else an error code. 2029 - */ 2030 - int gpiod_direction_output(struct gpio_desc *desc, int value) 1759 + static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) 2031 1760 { 2032 1761 unsigned long flags; 2033 1762 struct gpio_chip *chip; 2034 1763 int status = -EINVAL; 2035 1764 int offset; 2036 - 2037 - if (!desc || !desc->chip) { 2038 - pr_warn("%s: invalid GPIO\n", __func__); 2039 - return -EINVAL; 2040 - } 2041 1765 2042 1766 /* GPIOs used for IRQs shall not be set as output */ 2043 1767 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { ··· 2085 1839 if (status) 2086 1840 gpiod_dbg(desc, "%s: gpio status %d\n", __func__, status); 2087 1841 return status; 1842 + } 1843 + 1844 + /** 1845 + * gpiod_direction_output_raw - set the GPIO direction to output 1846 + * @desc: GPIO to set to output 1847 + * @value: initial output value of the GPIO 1848 + * 1849 + * Set the direction of the passed GPIO to output, such as gpiod_set_value() can 1850 + * be called safely on it. The initial value of the output must be specified 1851 + * as raw value on the physical line without regard for the ACTIVE_LOW status. 1852 + * 1853 + * Return 0 in case of success, else an error code. 1854 + */ 1855 + int gpiod_direction_output_raw(struct gpio_desc *desc, int value) 1856 + { 1857 + if (!desc || !desc->chip) { 1858 + pr_warn("%s: invalid GPIO\n", __func__); 1859 + return -EINVAL; 1860 + } 1861 + return _gpiod_direction_output_raw(desc, value); 1862 + } 1863 + EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); 1864 + 1865 + /** 1866 + * gpiod_direction_output - set the GPIO direction to output 1867 + * @desc: GPIO to set to output 1868 + * @value: initial output value of the GPIO 1869 + * 1870 + * Set the direction of the passed GPIO to output, such as gpiod_set_value() can 1871 + * be called safely on it. The initial value of the output must be specified 1872 + * as the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into 1873 + * account. 1874 + * 1875 + * Return 0 in case of success, else an error code. 1876 + */ 1877 + int gpiod_direction_output(struct gpio_desc *desc, int value) 1878 + { 1879 + if (!desc || !desc->chip) { 1880 + pr_warn("%s: invalid GPIO\n", __func__); 1881 + return -EINVAL; 1882 + } 1883 + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 1884 + value = !value; 1885 + return _gpiod_direction_output_raw(desc, value); 2088 1886 } 2089 1887 EXPORT_SYMBOL_GPL(gpiod_direction_output); 2090 1888 ··· 2218 1928 * that the GPIO was actually requested. 2219 1929 */ 2220 1930 2221 - static int _gpiod_get_raw_value(const struct gpio_desc *desc) 1931 + static bool _gpiod_get_raw_value(const struct gpio_desc *desc) 2222 1932 { 2223 1933 struct gpio_chip *chip; 2224 - int value; 1934 + bool value; 2225 1935 int offset; 2226 1936 2227 1937 chip = desc->chip; 2228 1938 offset = gpio_chip_hwgpio(desc); 2229 - value = chip->get ? chip->get(chip, offset) : 0; 1939 + value = chip->get ? chip->get(chip, offset) : false; 2230 1940 trace_gpio_value(desc_to_gpio(desc), 1, value); 2231 1941 return value; 2232 1942 } ··· 2282 1992 * @desc: gpio descriptor whose state need to be set. 2283 1993 * @value: Non-zero for setting it HIGH otherise it will set to LOW. 2284 1994 */ 2285 - static void _gpio_set_open_drain_value(struct gpio_desc *desc, int value) 1995 + static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value) 2286 1996 { 2287 1997 int err = 0; 2288 1998 struct gpio_chip *chip = desc->chip; ··· 2309 2019 * @desc: gpio descriptor whose state need to be set. 2310 2020 * @value: Non-zero for setting it HIGH otherise it will set to LOW. 2311 2021 */ 2312 - static void _gpio_set_open_source_value(struct gpio_desc *desc, int value) 2022 + static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value) 2313 2023 { 2314 2024 int err = 0; 2315 2025 struct gpio_chip *chip = desc->chip; ··· 2331 2041 __func__, err); 2332 2042 } 2333 2043 2334 - static void _gpiod_set_raw_value(struct gpio_desc *desc, int value) 2044 + static void _gpiod_set_raw_value(struct gpio_desc *desc, bool value) 2335 2045 { 2336 2046 struct gpio_chip *chip; 2337 2047 ··· 2427 2137 * @gpio: the GPIO line to lock as used for IRQ 2428 2138 * 2429 2139 * This is used directly by GPIO drivers that want to lock down 2430 - * a certain GPIO line to be used as IRQs, for example in the 2431 - * .to_irq() callback of their gpio_chip, or in the .irq_enable() 2432 - * of its irq_chip implementation if the GPIO is known from that 2433 - * code. 2140 + * a certain GPIO line to be used for IRQs. 2434 2141 */ 2435 2142 int gpiod_lock_as_irq(struct gpio_desc *desc) 2436 2143 { ··· 2448 2161 2449 2162 int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 2450 2163 { 2451 - return gpiod_lock_as_irq(gpiochip_offset_to_desc(chip, offset)); 2164 + return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset)); 2452 2165 } 2453 2166 EXPORT_SYMBOL_GPL(gpio_lock_as_irq); 2454 2167 ··· 2470 2183 2471 2184 void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 2472 2185 { 2473 - return gpiod_unlock_as_irq(gpiochip_offset_to_desc(chip, offset)); 2186 + return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset)); 2474 2187 } 2475 2188 EXPORT_SYMBOL_GPL(gpio_unlock_as_irq); 2476 2189 ··· 2691 2404 return ERR_PTR(-EINVAL); 2692 2405 } 2693 2406 2694 - desc = gpiochip_offset_to_desc(chip, p->chip_hwnum); 2407 + desc = gpiochip_get_desc(chip, p->chip_hwnum); 2695 2408 *flags = p->flags; 2696 2409 2697 2410 return desc;
+3
drivers/gpio/gpiolib.h
··· 43 43 } 44 44 #endif 45 45 46 + int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label); 47 + void gpiochip_free_own_desc(struct gpio_desc *desc); 48 + 46 49 #endif /* GPIOLIB_H */
+4
drivers/pinctrl/Kconfig
··· 235 235 depends on ARCH_U8500 || ARCH_NOMADIK 236 236 select PINMUX 237 237 select PINCONF 238 + select GPIOLIB 239 + select OF_GPIO 240 + select GPIOLIB_IRQCHIP 238 241 239 242 config PINCTRL_STN8815 240 243 bool "STN8815 pin controller driver" ··· 324 321 config PINCTRL_COH901 325 322 bool "ST-Ericsson U300 COH 901 335/571 GPIO" 326 323 depends on GPIOLIB && ARCH_U300 && PINCTRL_U300 324 + select GPIOLIB_IRQCHIP 327 325 help 328 326 Say yes here to support GPIO interface on ST-Ericsson U300. 329 327 The names of the two IP block variants supported are
+1
drivers/pinctrl/pinctrl-adi2.c
··· 337 337 338 338 if (!port) { 339 339 pr_err("GPIO IRQ %d :Not exist\n", d->irq); 340 + /* FIXME: negative return code will be ignored */ 340 341 return -ENODEV; 341 342 } 342 343
+7 -7
drivers/pinctrl/pinctrl-baytrail.c
··· 407 407 { 408 408 } 409 409 410 - static unsigned int byt_irq_startup(struct irq_data *d) 410 + static int byt_irq_reqres(struct irq_data *d) 411 411 { 412 412 struct byt_gpio *vg = irq_data_get_irq_chip_data(d); 413 413 414 - if (gpio_lock_as_irq(&vg->chip, irqd_to_hwirq(d))) 414 + if (gpio_lock_as_irq(&vg->chip, irqd_to_hwirq(d))) { 415 415 dev_err(vg->chip.dev, 416 416 "unable to lock HW IRQ %lu for IRQ\n", 417 417 irqd_to_hwirq(d)); 418 - byt_irq_unmask(d); 418 + return -EINVAL; 419 + } 419 420 return 0; 420 421 } 421 422 422 - static void byt_irq_shutdown(struct irq_data *d) 423 + static void byt_irq_relres(struct irq_data *d) 423 424 { 424 425 struct byt_gpio *vg = irq_data_get_irq_chip_data(d); 425 426 426 - byt_irq_mask(d); 427 427 gpio_unlock_as_irq(&vg->chip, irqd_to_hwirq(d)); 428 428 } 429 429 ··· 432 432 .irq_mask = byt_irq_mask, 433 433 .irq_unmask = byt_irq_unmask, 434 434 .irq_set_type = byt_irq_type, 435 - .irq_startup = byt_irq_startup, 436 - .irq_shutdown = byt_irq_shutdown, 435 + .irq_request_resources = byt_irq_reqres, 436 + .irq_release_resources = byt_irq_relres, 437 437 }; 438 438 439 439 static void byt_gpio_irq_init_hw(struct byt_gpio *vg)
+59 -139
drivers/pinctrl/pinctrl-coh901.c
··· 8 8 * Author: Jonas Aaberg <jonas.aberg@stericsson.com> 9 9 */ 10 10 #include <linux/module.h> 11 - #include <linux/irq.h> 12 11 #include <linux/interrupt.h> 13 12 #include <linux/delay.h> 14 13 #include <linux/errno.h> 15 14 #include <linux/io.h> 16 - #include <linux/irqdomain.h> 17 15 #include <linux/clk.h> 18 16 #include <linux/err.h> 19 17 #include <linux/platform_device.h> 20 18 #include <linux/gpio.h> 21 - #include <linux/list.h> 22 19 #include <linux/slab.h> 23 20 #include <linux/pinctrl/consumer.h> 24 21 #include <linux/pinctrl/pinconf-generic.h> ··· 58 61 #define U300_GPIO_PINS_PER_PORT 8 59 62 #define U300_GPIO_MAX (U300_GPIO_PINS_PER_PORT * U300_GPIO_NUM_PORTS) 60 63 64 + struct u300_gpio_port { 65 + struct u300_gpio *gpio; 66 + char name[8]; 67 + int irq; 68 + int number; 69 + u8 toggle_edge_mode; 70 + }; 71 + 61 72 struct u300_gpio { 62 73 struct gpio_chip chip; 63 - struct list_head port_list; 74 + struct u300_gpio_port ports[U300_GPIO_NUM_PORTS]; 64 75 struct clk *clk; 65 76 void __iomem *base; 66 77 struct device *dev; ··· 81 76 u32 icr; 82 77 u32 ien; 83 78 u32 iev; 84 - }; 85 - 86 - struct u300_gpio_port { 87 - struct list_head node; 88 - struct u300_gpio *gpio; 89 - char name[8]; 90 - struct irq_domain *domain; 91 - int irq; 92 - int number; 93 - u8 toggle_edge_mode; 94 79 }; 95 80 96 81 /* ··· 303 308 return 0; 304 309 } 305 310 306 - static int u300_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 307 - { 308 - struct u300_gpio *gpio = to_u300_gpio(chip); 309 - int portno = offset >> 3; 310 - struct u300_gpio_port *port = NULL; 311 - struct list_head *p; 312 - int retirq; 313 - bool found = false; 314 - 315 - list_for_each(p, &gpio->port_list) { 316 - port = list_entry(p, struct u300_gpio_port, node); 317 - if (port->number == portno) { 318 - found = true; 319 - break; 320 - } 321 - } 322 - if (!found) { 323 - dev_err(gpio->dev, "could not locate port for GPIO %d IRQ\n", 324 - offset); 325 - return -EINVAL; 326 - } 327 - 328 - /* 329 - * The local hwirqs on the port are the lower three bits, there 330 - * are exactly 8 IRQs per port since they are 8-bit 331 - */ 332 - retirq = irq_find_mapping(port->domain, (offset & 0x7)); 333 - 334 - dev_dbg(gpio->dev, "request IRQ for GPIO %d, return %d from port %d\n", 335 - offset, retirq, port->number); 336 - return retirq; 337 - } 338 - 339 311 /* Returning -EINVAL means "supported but not available" */ 340 312 int u300_gpio_config_get(struct gpio_chip *chip, 341 313 unsigned offset, ··· 423 461 .set = u300_gpio_set, 424 462 .direction_input = u300_gpio_direction_input, 425 463 .direction_output = u300_gpio_direction_output, 426 - .to_irq = u300_gpio_to_irq, 427 464 }; 428 465 429 466 static void u300_toggle_trigger(struct u300_gpio *gpio, unsigned offset) ··· 446 485 447 486 static int u300_gpio_irq_type(struct irq_data *d, unsigned trigger) 448 487 { 449 - struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); 450 - struct u300_gpio *gpio = port->gpio; 451 - int offset = (port->number << 3) + d->hwirq; 488 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 489 + struct u300_gpio *gpio = to_u300_gpio(chip); 490 + struct u300_gpio_port *port = &gpio->ports[d->hwirq >> 3]; 491 + int offset = d->hwirq; 452 492 u32 val; 453 493 454 494 if ((trigger & IRQF_TRIGGER_RISING) && ··· 483 521 484 522 static void u300_gpio_irq_enable(struct irq_data *d) 485 523 { 486 - struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); 487 - struct u300_gpio *gpio = port->gpio; 488 - int offset = (port->number << 3) + d->hwirq; 524 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 525 + struct u300_gpio *gpio = to_u300_gpio(chip); 526 + struct u300_gpio_port *port = &gpio->ports[d->hwirq >> 3]; 527 + int offset = d->hwirq; 489 528 u32 val; 490 529 unsigned long flags; 491 530 492 531 dev_dbg(gpio->dev, "enable IRQ for hwirq %lu on port %s, offset %d\n", 493 532 d->hwirq, port->name, offset); 494 - if (gpio_lock_as_irq(&gpio->chip, d->hwirq)) 495 - dev_err(gpio->dev, 496 - "unable to lock HW IRQ %lu for IRQ\n", 497 - d->hwirq); 498 533 local_irq_save(flags); 499 534 val = readl(U300_PIN_REG(offset, ien)); 500 535 writel(val | U300_PIN_BIT(offset), U300_PIN_REG(offset, ien)); ··· 500 541 501 542 static void u300_gpio_irq_disable(struct irq_data *d) 502 543 { 503 - struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); 504 - struct u300_gpio *gpio = port->gpio; 505 - int offset = (port->number << 3) + d->hwirq; 544 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 545 + struct u300_gpio *gpio = to_u300_gpio(chip); 546 + int offset = d->hwirq; 506 547 u32 val; 507 548 unsigned long flags; 508 549 ··· 510 551 val = readl(U300_PIN_REG(offset, ien)); 511 552 writel(val & ~U300_PIN_BIT(offset), U300_PIN_REG(offset, ien)); 512 553 local_irq_restore(flags); 513 - gpio_unlock_as_irq(&gpio->chip, d->hwirq); 514 554 } 515 555 516 556 static struct irq_chip u300_gpio_irqchip = { ··· 517 559 .irq_enable = u300_gpio_irq_enable, 518 560 .irq_disable = u300_gpio_irq_disable, 519 561 .irq_set_type = u300_gpio_irq_type, 520 - 521 562 }; 522 563 523 564 static void u300_gpio_irq_handler(unsigned irq, struct irq_desc *desc) 524 565 { 525 - struct u300_gpio_port *port = irq_get_handler_data(irq); 526 - struct u300_gpio *gpio = port->gpio; 566 + struct irq_chip *parent_chip = irq_get_chip(irq); 567 + struct gpio_chip *chip = irq_get_handler_data(irq); 568 + struct u300_gpio *gpio = to_u300_gpio(chip); 569 + struct u300_gpio_port *port = &gpio->ports[irq - chip->base]; 527 570 int pinoffset = port->number << 3; /* get the right stride */ 528 571 unsigned long val; 529 572 530 - desc->irq_data.chip->irq_ack(&desc->irq_data); 573 + chained_irq_enter(parent_chip, desc); 574 + 531 575 /* Read event register */ 532 576 val = readl(U300_PIN_REG(pinoffset, iev)); 533 577 /* Mask relevant bits */ ··· 542 582 int irqoffset; 543 583 544 584 for_each_set_bit(irqoffset, &val, U300_GPIO_PINS_PER_PORT) { 545 - int pin_irq = irq_find_mapping(port->domain, irqoffset); 546 585 int offset = pinoffset + irqoffset; 586 + int pin_irq = irq_find_mapping(chip->irqdomain, offset); 547 587 548 588 dev_dbg(gpio->dev, "GPIO IRQ %d on pin %d\n", 549 589 pin_irq, offset); ··· 557 597 } 558 598 } 559 599 560 - desc->irq_data.chip->irq_unmask(&desc->irq_data); 600 + chained_irq_exit(parent_chip, desc); 561 601 } 562 602 563 603 static void __init u300_gpio_init_pin(struct u300_gpio *gpio, ··· 605 645 conf = &bs335_gpio_config[i][j]; 606 646 u300_gpio_init_pin(gpio, offset, conf); 607 647 } 608 - } 609 - } 610 - 611 - static inline void u300_gpio_free_ports(struct u300_gpio *gpio) 612 - { 613 - struct u300_gpio_port *port; 614 - struct list_head *p, *n; 615 - 616 - list_for_each_safe(p, n, &gpio->port_list) { 617 - port = list_entry(p, struct u300_gpio_port, node); 618 - list_del(&port->node); 619 - if (port->domain) 620 - irq_domain_remove(port->domain); 621 - kfree(port); 622 648 } 623 649 } 624 650 ··· 698 752 gpio->base + U300_GPIO_CR); 699 753 u300_gpio_init_coh901571(gpio); 700 754 701 - /* Add each port with its IRQ separately */ 702 - INIT_LIST_HEAD(&gpio->port_list); 703 - for (portno = 0 ; portno < U300_GPIO_NUM_PORTS; portno++) { 704 - struct u300_gpio_port *port = 705 - kmalloc(sizeof(struct u300_gpio_port), GFP_KERNEL); 706 - 707 - if (!port) { 708 - dev_err(gpio->dev, "out of memory\n"); 709 - err = -ENOMEM; 710 - goto err_no_port; 711 - } 712 - 713 - snprintf(port->name, 8, "gpio%d", portno); 714 - port->number = portno; 715 - port->gpio = gpio; 716 - 717 - port->irq = platform_get_irq(pdev, portno); 718 - 719 - dev_dbg(gpio->dev, "register IRQ %d for port %s\n", port->irq, 720 - port->name); 721 - 722 - port->domain = irq_domain_add_linear(pdev->dev.of_node, 723 - U300_GPIO_PINS_PER_PORT, 724 - &irq_domain_simple_ops, 725 - port); 726 - if (!port->domain) { 727 - err = -ENOMEM; 728 - goto err_no_domain; 729 - } 730 - 731 - irq_set_chained_handler(port->irq, u300_gpio_irq_handler); 732 - irq_set_handler_data(port->irq, port); 733 - 734 - /* For each GPIO pin set the unique IRQ handler */ 735 - for (i = 0; i < U300_GPIO_PINS_PER_PORT; i++) { 736 - int irqno = irq_create_mapping(port->domain, i); 737 - 738 - dev_dbg(gpio->dev, "GPIO%d on port %s gets IRQ %d\n", 739 - gpio->chip.base + (port->number << 3) + i, 740 - port->name, irqno); 741 - irq_set_chip_and_handler(irqno, &u300_gpio_irqchip, 742 - handle_simple_irq); 743 - set_irq_flags(irqno, IRQF_VALID); 744 - irq_set_chip_data(irqno, port); 745 - } 746 - 747 - /* Turns off irq force (test register) for this port */ 748 - writel(0x0, gpio->base + portno * gpio->stride + ifr); 749 - 750 - list_add_tail(&port->node, &gpio->port_list); 751 - } 752 - dev_dbg(gpio->dev, "initialized %d GPIO ports\n", portno); 753 - 754 755 #ifdef CONFIG_OF_GPIO 755 756 gpio->chip.of_node = pdev->dev.of_node; 756 757 #endif ··· 706 813 dev_err(gpio->dev, "unable to add gpiochip: %d\n", err); 707 814 goto err_no_chip; 708 815 } 816 + 817 + err = gpiochip_irqchip_add(&gpio->chip, 818 + &u300_gpio_irqchip, 819 + 0, 820 + handle_simple_irq, 821 + IRQ_TYPE_EDGE_FALLING); 822 + if (err) { 823 + dev_err(gpio->dev, "no GPIO irqchip\n"); 824 + goto err_no_irqchip; 825 + } 826 + 827 + /* Add each port with its IRQ separately */ 828 + for (portno = 0 ; portno < U300_GPIO_NUM_PORTS; portno++) { 829 + struct u300_gpio_port *port = &gpio->ports[portno]; 830 + 831 + snprintf(port->name, 8, "gpio%d", portno); 832 + port->number = portno; 833 + port->gpio = gpio; 834 + 835 + port->irq = platform_get_irq(pdev, portno); 836 + 837 + gpiochip_set_chained_irqchip(&gpio->chip, 838 + &u300_gpio_irqchip, 839 + port->irq, 840 + u300_gpio_irq_handler); 841 + 842 + /* Turns off irq force (test register) for this port */ 843 + writel(0x0, gpio->base + portno * gpio->stride + ifr); 844 + } 845 + dev_dbg(gpio->dev, "initialized %d GPIO ports\n", portno); 709 846 710 847 /* 711 848 * Add pinctrl pin ranges, the pin controller must be registered ··· 755 832 return 0; 756 833 757 834 err_no_range: 835 + err_no_irqchip: 758 836 if (gpiochip_remove(&gpio->chip)) 759 837 dev_err(&pdev->dev, "failed to remove gpio chip\n"); 760 838 err_no_chip: 761 - err_no_domain: 762 - err_no_port: 763 - u300_gpio_free_ports(gpio); 764 839 clk_disable_unprepare(gpio->clk); 765 840 dev_err(&pdev->dev, "module ERROR:%d\n", err); 766 841 return err; ··· 777 856 dev_err(gpio->dev, "unable to remove gpiochip: %d\n", err); 778 857 return err; 779 858 } 780 - u300_gpio_free_ports(gpio); 781 859 clk_disable_unprepare(gpio->clk); 782 860 return 0; 783 861 }
+5 -6
drivers/pinctrl/pinctrl-msm.c
··· 785 785 return 0; 786 786 } 787 787 788 - static unsigned int msm_gpio_irq_startup(struct irq_data *d) 788 + static int msm_gpio_irq_reqres(struct irq_data *d) 789 789 { 790 790 struct msm_pinctrl *pctrl = irq_data_get_irq_chip_data(d); 791 791 792 792 if (gpio_lock_as_irq(&pctrl->chip, d->hwirq)) { 793 793 dev_err(pctrl->dev, "unable to lock HW IRQ %lu for IRQ\n", 794 794 d->hwirq); 795 + return -EINVAL; 795 796 } 796 - msm_gpio_irq_unmask(d); 797 797 return 0; 798 798 } 799 799 800 - static void msm_gpio_irq_shutdown(struct irq_data *d) 800 + static void msm_gpio_irq_relres(struct irq_data *d) 801 801 { 802 802 struct msm_pinctrl *pctrl = irq_data_get_irq_chip_data(d); 803 803 804 - msm_gpio_irq_mask(d); 805 804 gpio_unlock_as_irq(&pctrl->chip, d->hwirq); 806 805 } 807 806 ··· 811 812 .irq_ack = msm_gpio_irq_ack, 812 813 .irq_set_type = msm_gpio_irq_set_type, 813 814 .irq_set_wake = msm_gpio_irq_set_wake, 814 - .irq_startup = msm_gpio_irq_startup, 815 - .irq_shutdown = msm_gpio_irq_shutdown, 815 + .irq_request_resources = msm_gpio_irq_reqres, 816 + .irq_release_resources = msm_gpio_irq_relres, 816 817 }; 817 818 818 819 static void msm_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
+49 -110
drivers/pinctrl/pinctrl-nomadik.c
··· 21 21 #include <linux/gpio.h> 22 22 #include <linux/spinlock.h> 23 23 #include <linux/interrupt.h> 24 - #include <linux/irq.h> 25 - #include <linux/irqdomain.h> 26 - #include <linux/irqchip/chained_irq.h> 27 24 #include <linux/slab.h> 28 25 #include <linux/of_device.h> 29 26 #include <linux/of_address.h> ··· 243 246 NMK_GPIO_SLPM_WAKEUP_DISABLE = NMK_GPIO_SLPM_NOCHANGE, 244 247 }; 245 248 246 - /* 247 - * Platform data to register a block: only the initial gpio/irq number. 248 - */ 249 - struct nmk_gpio_platform_data { 250 - char *name; 251 - int first_gpio; 252 - int first_irq; 253 - int num_gpio; 254 - u32 (*get_secondary_status)(unsigned int bank); 255 - void (*set_ioforce)(bool enable); 256 - bool supports_sleepmode; 257 - }; 258 - 259 249 struct nmk_gpio_chip { 260 250 struct gpio_chip chip; 261 - struct irq_domain *domain; 262 251 void __iomem *addr; 263 252 struct clk *clk; 264 253 unsigned int bank; 265 254 unsigned int parent_irq; 266 - int secondary_parent_irq; 267 - u32 (*get_secondary_status)(unsigned int bank); 255 + int latent_parent_irq; 256 + u32 (*get_latent_status)(unsigned int bank); 268 257 void (*set_ioforce)(bool enable); 269 258 spinlock_t lock; 270 259 bool sleepmode; ··· 415 432 u32 falling = nmk_chip->fimsc & BIT(offset); 416 433 u32 rising = nmk_chip->rimsc & BIT(offset); 417 434 int gpio = nmk_chip->chip.base + offset; 418 - int irq = irq_find_mapping(nmk_chip->domain, offset); 435 + int irq = irq_find_mapping(nmk_chip->chip.irqdomain, offset); 419 436 struct irq_data *d = irq_get_irq_data(irq); 420 437 421 438 if (!rising && !falling) ··· 643 660 644 661 static void nmk_gpio_irq_ack(struct irq_data *d) 645 662 { 646 - struct nmk_gpio_chip *nmk_chip; 647 - 648 - nmk_chip = irq_data_get_irq_chip_data(d); 649 - if (!nmk_chip) 650 - return; 663 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 664 + struct nmk_gpio_chip *nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 651 665 652 666 clk_enable(nmk_chip->clk); 653 667 writel(nmk_gpio_get_bitmask(d->hwirq), nmk_chip->addr + NMK_GPIO_IC); ··· 828 848 { 829 849 struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d); 830 850 831 - if (gpio_lock_as_irq(&nmk_chip->chip, d->hwirq)) 832 - dev_err(nmk_chip->chip.dev, 833 - "unable to lock HW IRQ %lu for IRQ\n", 834 - d->hwirq); 835 851 clk_enable(nmk_chip->clk); 836 852 nmk_gpio_irq_unmask(d); 837 853 return 0; ··· 839 863 840 864 nmk_gpio_irq_mask(d); 841 865 clk_disable(nmk_chip->clk); 842 - gpio_unlock_as_irq(&nmk_chip->chip, d->hwirq); 843 866 } 844 867 845 868 static struct irq_chip nmk_gpio_irq_chip = { ··· 856 881 static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc, 857 882 u32 status) 858 883 { 859 - struct nmk_gpio_chip *nmk_chip; 860 884 struct irq_chip *host_chip = irq_get_chip(irq); 885 + struct gpio_chip *chip = irq_desc_get_handler_data(desc); 861 886 862 887 chained_irq_enter(host_chip, desc); 863 888 864 - nmk_chip = irq_get_handler_data(irq); 865 889 while (status) { 866 890 int bit = __ffs(status); 867 891 868 - generic_handle_irq(irq_find_mapping(nmk_chip->domain, bit)); 892 + generic_handle_irq(irq_find_mapping(chip->irqdomain, bit)); 869 893 status &= ~BIT(bit); 870 894 } 871 895 ··· 873 899 874 900 static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 875 901 { 876 - struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq); 902 + struct gpio_chip *chip = irq_desc_get_handler_data(desc); 903 + struct nmk_gpio_chip *nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 877 904 u32 status; 878 905 906 + pr_err("PLONK IRQ %d\n", irq); 879 907 clk_enable(nmk_chip->clk); 880 908 status = readl(nmk_chip->addr + NMK_GPIO_IS); 881 909 clk_disable(nmk_chip->clk); ··· 885 909 __nmk_gpio_irq_handler(irq, desc, status); 886 910 } 887 911 888 - static void nmk_gpio_secondary_irq_handler(unsigned int irq, 912 + static void nmk_gpio_latent_irq_handler(unsigned int irq, 889 913 struct irq_desc *desc) 890 914 { 891 - struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq); 892 - u32 status = nmk_chip->get_secondary_status(nmk_chip->bank); 915 + struct gpio_chip *chip = irq_desc_get_handler_data(desc); 916 + struct nmk_gpio_chip *nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 917 + u32 status = nmk_chip->get_latent_status(nmk_chip->bank); 893 918 894 919 __nmk_gpio_irq_handler(irq, desc, status); 895 - } 896 - 897 - static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip) 898 - { 899 - irq_set_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler); 900 - irq_set_handler_data(nmk_chip->parent_irq, nmk_chip); 901 - 902 - if (nmk_chip->secondary_parent_irq >= 0) { 903 - irq_set_chained_handler(nmk_chip->secondary_parent_irq, 904 - nmk_gpio_secondary_irq_handler); 905 - irq_set_handler_data(nmk_chip->secondary_parent_irq, nmk_chip); 906 - } 907 - 908 - return 0; 909 920 } 910 921 911 922 /* I/O Functions */ ··· 971 1008 clk_disable(nmk_chip->clk); 972 1009 973 1010 return 0; 974 - } 975 - 976 - static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 977 - { 978 - struct nmk_gpio_chip *nmk_chip = 979 - container_of(chip, struct nmk_gpio_chip, chip); 980 - 981 - return irq_create_mapping(nmk_chip->domain, offset); 982 1011 } 983 1012 984 1013 #ifdef CONFIG_DEBUG_FS ··· 1071 1116 .get = nmk_gpio_get_input, 1072 1117 .direction_output = nmk_gpio_make_output, 1073 1118 .set = nmk_gpio_set_output, 1074 - .to_irq = nmk_gpio_to_irq, 1075 1119 .dbg_show = nmk_gpio_dbg_show, 1076 1120 .can_sleep = false, 1077 1121 }; ··· 1171 1217 } 1172 1218 } 1173 1219 1174 - static int nmk_gpio_irq_map(struct irq_domain *d, unsigned int irq, 1175 - irq_hw_number_t hwirq) 1176 - { 1177 - struct nmk_gpio_chip *nmk_chip = d->host_data; 1178 - 1179 - if (!nmk_chip) 1180 - return -EINVAL; 1181 - 1182 - irq_set_chip_and_handler(irq, &nmk_gpio_irq_chip, handle_edge_irq); 1183 - set_irq_flags(irq, IRQF_VALID); 1184 - irq_set_chip_data(irq, nmk_chip); 1185 - irq_set_irq_type(irq, IRQ_TYPE_EDGE_FALLING); 1186 - 1187 - return 0; 1188 - } 1189 - 1190 - static const struct irq_domain_ops nmk_gpio_irq_simple_ops = { 1191 - .map = nmk_gpio_irq_map, 1192 - .xlate = irq_domain_xlate_twocell, 1193 - }; 1194 - 1195 1220 static int nmk_gpio_probe(struct platform_device *dev) 1196 1221 { 1197 - struct nmk_gpio_platform_data *pdata; 1198 1222 struct device_node *np = dev->dev.of_node; 1199 1223 struct nmk_gpio_chip *nmk_chip; 1200 1224 struct gpio_chip *chip; 1201 1225 struct resource *res; 1202 1226 struct clk *clk; 1203 - int secondary_irq; 1227 + int latent_irq; 1228 + bool supports_sleepmode; 1204 1229 void __iomem *base; 1205 1230 int irq; 1206 1231 int ret; 1207 1232 1208 - pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); 1209 - if (!pdata) 1210 - return -ENOMEM; 1211 - 1212 1233 if (of_get_property(np, "st,supports-sleepmode", NULL)) 1213 - pdata->supports_sleepmode = true; 1234 + supports_sleepmode = true; 1235 + else 1236 + supports_sleepmode = false; 1214 1237 1215 1238 if (of_property_read_u32(np, "gpio-bank", &dev->id)) { 1216 1239 dev_err(&dev->dev, "gpio-bank property not found\n"); 1217 1240 return -EINVAL; 1218 1241 } 1219 1242 1220 - pdata->first_gpio = dev->id * NMK_GPIO_PER_CHIP; 1221 - pdata->num_gpio = NMK_GPIO_PER_CHIP; 1222 - 1223 1243 irq = platform_get_irq(dev, 0); 1224 1244 if (irq < 0) 1225 1245 return irq; 1226 1246 1227 - secondary_irq = platform_get_irq(dev, 1); 1228 - if (secondary_irq >= 0 && !pdata->get_secondary_status) 1229 - return -EINVAL; 1247 + /* It's OK for this IRQ not to be present */ 1248 + latent_irq = platform_get_irq(dev, 1); 1230 1249 1231 1250 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 1232 1251 base = devm_ioremap_resource(&dev->dev, res); ··· 1224 1297 nmk_chip->addr = base; 1225 1298 nmk_chip->chip = nmk_gpio_template; 1226 1299 nmk_chip->parent_irq = irq; 1227 - nmk_chip->secondary_parent_irq = secondary_irq; 1228 - nmk_chip->get_secondary_status = pdata->get_secondary_status; 1229 - nmk_chip->set_ioforce = pdata->set_ioforce; 1230 - nmk_chip->sleepmode = pdata->supports_sleepmode; 1300 + nmk_chip->latent_parent_irq = latent_irq; 1301 + nmk_chip->sleepmode = supports_sleepmode; 1231 1302 spin_lock_init(&nmk_chip->lock); 1232 1303 1233 1304 chip = &nmk_chip->chip; 1234 - chip->base = pdata->first_gpio; 1235 - chip->ngpio = pdata->num_gpio; 1236 - chip->label = pdata->name ?: dev_name(&dev->dev); 1305 + chip->base = dev->id * NMK_GPIO_PER_CHIP; 1306 + chip->ngpio = NMK_GPIO_PER_CHIP; 1307 + chip->label = dev_name(&dev->dev); 1237 1308 chip->dev = &dev->dev; 1238 1309 chip->owner = THIS_MODULE; 1239 1310 ··· 1250 1325 1251 1326 platform_set_drvdata(dev, nmk_chip); 1252 1327 1253 - nmk_chip->domain = irq_domain_add_simple(np, 1254 - NMK_GPIO_PER_CHIP, 0, 1255 - &nmk_gpio_irq_simple_ops, nmk_chip); 1256 - if (!nmk_chip->domain) { 1257 - dev_err(&dev->dev, "failed to create irqdomain\n"); 1258 - /* Just do this, no matter if it fails */ 1328 + /* 1329 + * Let the generic code handle this edge IRQ, the the chained 1330 + * handler will perform the actual work of handling the parent 1331 + * interrupt. 1332 + */ 1333 + ret = gpiochip_irqchip_add(&nmk_chip->chip, 1334 + &nmk_gpio_irq_chip, 1335 + 0, 1336 + handle_edge_irq, 1337 + IRQ_TYPE_EDGE_FALLING); 1338 + if (ret) { 1339 + dev_err(&dev->dev, "could not add irqchip\n"); 1259 1340 ret = gpiochip_remove(&nmk_chip->chip); 1260 - return -ENOSYS; 1341 + return -ENODEV; 1261 1342 } 1262 - 1263 - nmk_gpio_init_irq(nmk_chip); 1343 + /* Then register the chain on the parent IRQ */ 1344 + gpiochip_set_chained_irqchip(&nmk_chip->chip, 1345 + &nmk_gpio_irq_chip, 1346 + nmk_chip->parent_irq, 1347 + nmk_gpio_irq_handler); 1348 + if (nmk_chip->latent_parent_irq > 0) 1349 + gpiochip_set_chained_irqchip(&nmk_chip->chip, 1350 + &nmk_gpio_irq_chip, 1351 + nmk_chip->latent_parent_irq, 1352 + nmk_gpio_latent_irq_handler); 1264 1353 1265 1354 dev_info(&dev->dev, "at address %p\n", nmk_chip->addr); 1266 1355
+7 -7
drivers/pinctrl/sirf/pinctrl-sirf.c
··· 595 595 return 0; 596 596 } 597 597 598 - static unsigned int sirfsoc_gpio_irq_startup(struct irq_data *d) 598 + static int sirfsoc_gpio_irq_reqres(struct irq_data *d) 599 599 { 600 600 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); 601 601 602 - if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE)) 602 + if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE)) { 603 603 dev_err(bank->chip.gc.dev, 604 604 "unable to lock HW IRQ %lu for IRQ\n", 605 605 d->hwirq); 606 - sirfsoc_gpio_irq_unmask(d); 606 + return -EINVAL; 607 + } 607 608 return 0; 608 609 } 609 610 610 - static void sirfsoc_gpio_irq_shutdown(struct irq_data *d) 611 + static void sirfsoc_gpio_irq_relres(struct irq_data *d) 611 612 { 612 613 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); 613 614 614 - sirfsoc_gpio_irq_mask(d); 615 615 gpio_unlock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); 616 616 } 617 617 ··· 621 621 .irq_mask = sirfsoc_gpio_irq_mask, 622 622 .irq_unmask = sirfsoc_gpio_irq_unmask, 623 623 .irq_set_type = sirfsoc_gpio_irq_type, 624 - .irq_startup = sirfsoc_gpio_irq_startup, 625 - .irq_shutdown = sirfsoc_gpio_irq_shutdown, 624 + .irq_request_resources = sirfsoc_gpio_irq_reqres, 625 + .irq_release_resources = sirfsoc_gpio_irq_relres, 626 626 }; 627 627 628 628 static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc)
+1 -1
include/asm-generic/gpio.h
··· 69 69 } 70 70 static inline int gpio_direction_output(unsigned gpio, int value) 71 71 { 72 - return gpiod_direction_output(gpio_to_desc(gpio), value); 72 + return gpiod_direction_output_raw(gpio_to_desc(gpio), value); 73 73 } 74 74 75 75 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
+1
include/linux/basic_mmio_gpio.h
··· 19 19 #include <linux/spinlock_types.h> 20 20 21 21 struct bgpio_pdata { 22 + const char *label; 22 23 int base; 23 24 int ngpio; 24 25 };
+7 -8
include/linux/gpio/consumer.h
··· 5 5 #include <linux/kernel.h> 6 6 7 7 struct device; 8 - struct gpio_chip; 9 8 10 9 /** 11 10 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are ··· 35 36 int gpiod_get_direction(const struct gpio_desc *desc); 36 37 int gpiod_direction_input(struct gpio_desc *desc); 37 38 int gpiod_direction_output(struct gpio_desc *desc, int value); 39 + int gpiod_direction_output_raw(struct gpio_desc *desc, int value); 38 40 39 41 /* Value get/set from non-sleeping context */ 40 42 int gpiod_get_value(const struct gpio_desc *desc); ··· 59 59 /* Convert between the old gpio_ and new gpiod_ interfaces */ 60 60 struct gpio_desc *gpio_to_desc(unsigned gpio); 61 61 int desc_to_gpio(const struct gpio_desc *desc); 62 - struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 63 62 64 63 #else /* CONFIG_GPIOLIB */ 65 64 ··· 115 116 return -ENOSYS; 116 117 } 117 118 static inline int gpiod_direction_output(struct gpio_desc *desc, int value) 119 + { 120 + /* GPIO can never have been requested */ 121 + WARN_ON(1); 122 + return -ENOSYS; 123 + } 124 + static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) 118 125 { 119 126 /* GPIO can never have been requested */ 120 127 WARN_ON(1); ··· 211 206 /* GPIO can never have been requested */ 212 207 WARN_ON(1); 213 208 return -EINVAL; 214 - } 215 - static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 216 - { 217 - /* GPIO can never have been requested */ 218 - WARN_ON(1); 219 - return ERR_PTR(-ENODEV); 220 209 } 221 210 222 211
+48
include/linux/gpio/driver.h
··· 3 3 4 4 #include <linux/types.h> 5 5 #include <linux/module.h> 6 + #include <linux/irq.h> 7 + #include <linux/irqchip/chained_irq.h> 8 + #include <linux/irqdomain.h> 6 9 7 10 struct device; 8 11 struct gpio_desc; 9 12 struct of_phandle_args; 10 13 struct device_node; 11 14 struct seq_file; 15 + 16 + #ifdef CONFIG_GPIOLIB 12 17 13 18 /** 14 19 * struct gpio_chip - abstract a GPIO controller ··· 100 95 bool can_sleep; 101 96 bool exported; 102 97 98 + #ifdef CONFIG_GPIOLIB_IRQCHIP 99 + /* 100 + * With CONFIG_GPIO_IRQCHIP we get an irqchip inside the gpiolib 101 + * to handle IRQs for most practical cases. 102 + */ 103 + struct irq_chip *irqchip; 104 + struct irq_domain *irqdomain; 105 + unsigned int irq_base; 106 + irq_flow_handler_t irq_handler; 107 + unsigned int irq_default_type; 108 + #endif 109 + 103 110 #if defined(CONFIG_OF_GPIO) 104 111 /* 105 112 * If CONFIG_OF is enabled, then all GPIO controllers described in the ··· 145 128 /* lock/unlock as IRQ */ 146 129 int gpiod_lock_as_irq(struct gpio_desc *desc); 147 130 void gpiod_unlock_as_irq(struct gpio_desc *desc); 131 + 132 + struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 133 + 134 + struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, 135 + u16 hwnum); 148 136 149 137 enum gpio_lookup_flags { 150 138 GPIO_ACTIVE_HIGH = (0 << 0), ··· 204 182 } 205 183 206 184 void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 185 + 186 + #ifdef CONFIG_GPIOLIB_IRQCHIP 187 + 188 + void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 189 + struct irq_chip *irqchip, 190 + int parent_irq, 191 + irq_flow_handler_t parent_handler); 192 + 193 + int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 194 + struct irq_chip *irqchip, 195 + unsigned int first_irq, 196 + irq_flow_handler_t handler, 197 + unsigned int type); 198 + 199 + #endif /* CONFIG_GPIO_IRQCHIP */ 200 + 201 + #else /* CONFIG_GPIOLIB */ 202 + 203 + static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 204 + { 205 + /* GPIO can never have been requested */ 206 + WARN_ON(1); 207 + return ERR_PTR(-ENODEV); 208 + } 209 + 210 + #endif /* CONFIG_GPIOLIB */ 207 211 208 212 #endif
+2 -2
include/linux/i2c/adp5588.h
··· 161 161 unsigned irq_base; /* interrupt base # */ 162 162 unsigned pullup_dis_mask; /* Pull-Up Disable Mask */ 163 163 int (*setup)(struct i2c_client *client, 164 - int gpio, unsigned ngpio, 164 + unsigned gpio, unsigned ngpio, 165 165 void *context); 166 166 int (*teardown)(struct i2c_client *client, 167 - int gpio, unsigned ngpio, 167 + unsigned gpio, unsigned ngpio, 168 168 void *context); 169 169 void *context; 170 170 };
-4
include/linux/platform_data/gpio-davinci.h
··· 21 21 22 22 #include <asm-generic/gpio.h> 23 23 24 - enum davinci_gpio_type { 25 - GPIO_TYPE_TNETV107X = 0, 26 - }; 27 - 28 24 struct davinci_gpio_platform_data { 29 25 u32 ngpio; 30 26 u32 gpio_unbanked;