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

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

Pull GPIO updates from Linus Walleij:
"This is the bulk of GPIO changes for the v5.8 kernel cycle.

Core changes:

- A new GPIO aggregator driver has been merged: this can join a few
select GPIO lines into a new aggregated GPIO chip. This can be used
for security: a process can be granted access to only these lines,
for example for industrial control. Another way to use this is to
reexpose certain select lines to a virtual machine or container.

- Warn if the gpio-line-names is too long in he DT parser core.

- GPIO lines can now be looked up by line name in addition to being
looked up by offset.

New drivers:

- A new generic regmap GPIO driver has been merged. Too many regmap
drivers are starting to look like each other so we need to create
some common ground and try to move drivers over to using that.

- The F7188X driver now supports F81865.

Driver improvements:

- Large improvements to the PCA953x expander, get multiple lines and
several cleanups.

- Large improvements to the DesignWare DWAPB driver, and Sergey Semin
has volunteered to maintain it.

- PL061 can now be built as a module, this is part of a bigger effort
to make the ARM platforms more modular"

* tag 'gpio-v5.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (77 commits)
gpio: pca953x: Drop unneeded ACPI_PTR()
MAINTAINERS: Add gpio regmap section
gpio: add a reusable generic gpio_chip using regmap
gpiolib: Introduce gpiochip_irqchip_add_domain()
gpio: gpiolib: Allow GPIO IRQs to lazy disable
gpiolib: Separate GPIO_GET_LINEINFO_WATCH_IOCTL conditional
gpio: rcar: Fix runtime PM imbalance on error
gpio: pca935x: Allow IRQ support for driver built as a module
gpio: pxa: Add COMPILE_TEST support
dt-bindings: gpio: Add renesas,em-gio bindings
MAINTAINERS: Fix file name for DesignWare GPIO DT schema
gpio: dwapb: Remove unneeded has_irq member in struct dwapb_port_property
gpio: dwapb: Don't use IRQ 0 as valid Linux interrupt
gpio: dwapb: avoid error message for optional IRQ
gpio: dwapb: Call acpi_gpiochip_free_interrupts() on GPIO chip de-registration
gpio: max730x: bring gpiochip_add_data after port config
MAINTAINERS: Add GPIO Aggregator section
docs: gpio: Add GPIO Aggregator documentation
gpio: Add GPIO Aggregator
gpiolib: Add support for GPIO lookup by line name
...

+1858 -446
+111
Documentation/admin-guide/gpio/gpio-aggregator.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0-only 2 + 3 + GPIO Aggregator 4 + =============== 5 + 6 + The GPIO Aggregator provides a mechanism to aggregate GPIOs, and expose them as 7 + a new gpio_chip. This supports the following use cases. 8 + 9 + 10 + Aggregating GPIOs using Sysfs 11 + ----------------------------- 12 + 13 + GPIO controllers are exported to userspace using /dev/gpiochip* character 14 + devices. Access control to these devices is provided by standard UNIX file 15 + system permissions, on an all-or-nothing basis: either a GPIO controller is 16 + accessible for a user, or it is not. 17 + 18 + The GPIO Aggregator provides access control for a set of one or more GPIOs, by 19 + aggregating them into a new gpio_chip, which can be assigned to a group or user 20 + using standard UNIX file ownership and permissions. Furthermore, this 21 + simplifies and hardens exporting GPIOs to a virtual machine, as the VM can just 22 + grab the full GPIO controller, and no longer needs to care about which GPIOs to 23 + grab and which not, reducing the attack surface. 24 + 25 + Aggregated GPIO controllers are instantiated and destroyed by writing to 26 + write-only attribute files in sysfs. 27 + 28 + /sys/bus/platform/drivers/gpio-aggregator/ 29 + 30 + "new_device" ... 31 + Userspace may ask the kernel to instantiate an aggregated GPIO 32 + controller by writing a string describing the GPIOs to 33 + aggregate to the "new_device" file, using the format 34 + 35 + .. code-block:: none 36 + 37 + [<gpioA>] [<gpiochipB> <offsets>] ... 38 + 39 + Where: 40 + 41 + "<gpioA>" ... 42 + is a GPIO line name, 43 + 44 + "<gpiochipB>" ... 45 + is a GPIO chip label, and 46 + 47 + "<offsets>" ... 48 + is a comma-separated list of GPIO offsets and/or 49 + GPIO offset ranges denoted by dashes. 50 + 51 + Example: Instantiate a new GPIO aggregator by aggregating GPIO 52 + line 19 of "e6052000.gpio" and GPIO lines 20-21 of 53 + "e6050000.gpio" into a new gpio_chip: 54 + 55 + .. code-block:: sh 56 + 57 + $ echo 'e6052000.gpio 19 e6050000.gpio 20-21' > new_device 58 + 59 + "delete_device" ... 60 + Userspace may ask the kernel to destroy an aggregated GPIO 61 + controller after use by writing its device name to the 62 + "delete_device" file. 63 + 64 + Example: Destroy the previously-created aggregated GPIO 65 + controller, assumed to be "gpio-aggregator.0": 66 + 67 + .. code-block:: sh 68 + 69 + $ echo gpio-aggregator.0 > delete_device 70 + 71 + 72 + Generic GPIO Driver 73 + ------------------- 74 + 75 + The GPIO Aggregator can also be used as a generic driver for a simple 76 + GPIO-operated device described in DT, without a dedicated in-kernel driver. 77 + This is useful in industrial control, and is not unlike e.g. spidev, which 78 + allows the user to communicate with an SPI device from userspace. 79 + 80 + Binding a device to the GPIO Aggregator is performed either by modifying the 81 + gpio-aggregator driver, or by writing to the "driver_override" file in Sysfs. 82 + 83 + Example: If "door" is a GPIO-operated device described in DT, using its own 84 + compatible value:: 85 + 86 + door { 87 + compatible = "myvendor,mydoor"; 88 + 89 + gpios = <&gpio2 19 GPIO_ACTIVE_HIGH>, 90 + <&gpio2 20 GPIO_ACTIVE_LOW>; 91 + gpio-line-names = "open", "lock"; 92 + }; 93 + 94 + it can be bound to the GPIO Aggregator by either: 95 + 96 + 1. Adding its compatible value to ``gpio_aggregator_dt_ids[]``, 97 + 2. Binding manually using "driver_override": 98 + 99 + .. code-block:: sh 100 + 101 + $ echo gpio-aggregator > /sys/bus/platform/devices/door/driver_override 102 + $ echo door > /sys/bus/platform/drivers/gpio-aggregator/bind 103 + 104 + After that, a new gpiochip "door" has been created: 105 + 106 + .. code-block:: sh 107 + 108 + $ gpioinfo door 109 + gpiochip12 - 2 lines: 110 + line 0: "open" unused input active-high 111 + line 1: "lock" unused input active-high
+1
Documentation/admin-guide/gpio/index.rst
··· 7 7 .. toctree:: 8 8 :maxdepth: 1 9 9 10 + gpio-aggregator 10 11 sysfs 11 12 12 13 .. only:: subproject and html
+70
Documentation/devicetree/bindings/gpio/renesas,em-gio.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/gpio/renesas,em-gio.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Renesas EMMA Mobile General Purpose I/O Interface 8 + 9 + maintainers: 10 + - Magnus Damm <magnus.damm@gmail.com> 11 + 12 + properties: 13 + compatible: 14 + const: renesas,em-gio 15 + 16 + reg: 17 + items: 18 + - description: First set of contiguous registers 19 + - description: Second set of contiguous registers 20 + 21 + interrupts: 22 + items: 23 + - description: Interrupt for the first set of 16 GPIO ports 24 + - description: Interrupt for the second set of 16 GPIO ports 25 + 26 + gpio-controller: true 27 + 28 + '#gpio-cells': 29 + const: 2 30 + 31 + gpio-ranges: 32 + maxItems: 1 33 + 34 + ngpios: 35 + minimum: 1 36 + maximum: 32 37 + 38 + interrupt-controller: true 39 + 40 + '#interrupt-cells': 41 + const: 2 42 + 43 + required: 44 + - compatible 45 + - reg 46 + - interrupts 47 + - gpio-controller 48 + - '#gpio-cells' 49 + - gpio-ranges 50 + - ngpios 51 + - interrupt-controller 52 + - '#interrupt-cells' 53 + 54 + additionalProperties: false 55 + 56 + examples: 57 + - | 58 + #include <dt-bindings/interrupt-controller/arm-gic.h> 59 + gpio0: gpio@e0050000 { 60 + compatible = "renesas,em-gio"; 61 + reg = <0xe0050000 0x2c>, <0xe0050040 0x20>; 62 + interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>, 63 + <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>; 64 + gpio-controller; 65 + #gpio-cells = <2>; 66 + gpio-ranges = <&pfc 0 0 32>; 67 + ngpios = <32>; 68 + interrupt-controller; 69 + #interrupt-cells = <2>; 70 + };
+134
Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/gpio/snps,dw-apb-gpio.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Synopsys DesignWare APB GPIO controller 8 + 9 + description: | 10 + Synopsys DesignWare GPIO controllers have a configurable number of ports, 11 + each of which are intended to be represented as child nodes with the generic 12 + GPIO-controller properties as desribed in this bindings file. 13 + 14 + maintainers: 15 + - Hoan Tran <hoan@os.amperecomputing.com> 16 + - Serge Semin <fancer.lancer@gmail.com> 17 + 18 + properties: 19 + $nodename: 20 + pattern: "^gpio@[0-9a-f]+$" 21 + 22 + compatible: 23 + const: snps,dw-apb-gpio 24 + 25 + "#address-cells": 26 + const: 1 27 + 28 + "#size-cells": 29 + const: 0 30 + 31 + reg: 32 + maxItems: 1 33 + 34 + clocks: 35 + minItems: 1 36 + items: 37 + - description: APB interface clock source 38 + - description: DW GPIO debounce reference clock source 39 + 40 + clock-names: 41 + minItems: 1 42 + items: 43 + - const: bus 44 + - const: db 45 + 46 + resets: 47 + maxItems: 1 48 + 49 + patternProperties: 50 + "^gpio-(port|controller)@[0-9a-f]+$": 51 + type: object 52 + properties: 53 + compatible: 54 + const: snps,dw-apb-gpio-port 55 + 56 + reg: 57 + maxItems: 1 58 + 59 + gpio-controller: true 60 + 61 + '#gpio-cells': 62 + const: 2 63 + 64 + snps,nr-gpios: 65 + description: The number of GPIO pins exported by the port. 66 + default: 32 67 + allOf: 68 + - $ref: /schemas/types.yaml#/definitions/uint32 69 + - minimum: 1 70 + maximum: 32 71 + 72 + interrupts: 73 + description: | 74 + The interrupts to the parent controller raised when GPIOs generate 75 + the interrupts. If the controller provides one combined interrupt 76 + for all GPIOs, specify a single interrupt. If the controller provides 77 + one interrupt for each GPIO, provide a list of interrupts that 78 + correspond to each of the GPIO pins. 79 + minItems: 1 80 + maxItems: 32 81 + 82 + interrupt-controller: true 83 + 84 + '#interrupt-cells': 85 + const: 2 86 + 87 + required: 88 + - compatible 89 + - reg 90 + - gpio-controller 91 + - '#gpio-cells' 92 + 93 + dependencies: 94 + interrupt-controller: [ interrupts ] 95 + 96 + additionalProperties: false 97 + 98 + additionalProperties: false 99 + 100 + required: 101 + - compatible 102 + - reg 103 + - "#address-cells" 104 + - "#size-cells" 105 + 106 + examples: 107 + - | 108 + gpio: gpio@20000 { 109 + compatible = "snps,dw-apb-gpio"; 110 + reg = <0x20000 0x1000>; 111 + #address-cells = <1>; 112 + #size-cells = <0>; 113 + 114 + porta: gpio-port@0 { 115 + compatible = "snps,dw-apb-gpio-port"; 116 + reg = <0>; 117 + gpio-controller; 118 + #gpio-cells = <2>; 119 + snps,nr-gpios = <8>; 120 + interrupt-controller; 121 + #interrupt-cells = <2>; 122 + interrupt-parent = <&vic1>; 123 + interrupts = <0>; 124 + }; 125 + 126 + portb: gpio-port@1 { 127 + compatible = "snps,dw-apb-gpio-port"; 128 + reg = <1>; 129 + gpio-controller; 130 + #gpio-cells = <2>; 131 + snps,nr-gpios = <8>; 132 + }; 133 + }; 134 + ...
-65
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/interrupt-controller/interrupts.txt 28 - - interrupts : The interrupts to the parent controller raised when GPIOs 29 - generate the interrupts. If the controller provides one combined interrupt 30 - for all GPIOs, specify a single interrupt. If the controller provides one 31 - interrupt for each GPIO, provide a list of interrupts that correspond to each 32 - of the GPIO pins. When specifying multiple interrupts, if any are unconnected, 33 - use the interrupts-extended property to specify the interrupts and set the 34 - interrupt controller handle for unused interrupts to 0. 35 - - snps,nr-gpios : The number of pins in the port, a single cell. 36 - - resets : Reset line for the controller. 37 - 38 - Example: 39 - 40 - gpio: gpio@20000 { 41 - compatible = "snps,dw-apb-gpio"; 42 - reg = <0x20000 0x1000>; 43 - #address-cells = <1>; 44 - #size-cells = <0>; 45 - 46 - porta: gpio@0 { 47 - compatible = "snps,dw-apb-gpio-port"; 48 - gpio-controller; 49 - #gpio-cells = <2>; 50 - snps,nr-gpios = <8>; 51 - reg = <0>; 52 - interrupt-controller; 53 - #interrupt-cells = <2>; 54 - interrupt-parent = <&vic1>; 55 - interrupts = <0>; 56 - }; 57 - 58 - portb: gpio@1 { 59 - compatible = "snps,dw-apb-gpio-port"; 60 - gpio-controller; 61 - #gpio-cells = <2>; 62 - snps,nr-gpios = <8>; 63 - reg = <1>; 64 - }; 65 - };
+10 -5
Documentation/driver-api/gpio/board.rst
··· 113 113 GPIOs are mapped by the means of tables of lookups, containing instances of the 114 114 gpiod_lookup structure. Two macros are defined to help declaring such mappings:: 115 115 116 - GPIO_LOOKUP(chip_label, chip_hwnum, con_id, flags) 117 - GPIO_LOOKUP_IDX(chip_label, chip_hwnum, con_id, idx, flags) 116 + GPIO_LOOKUP(key, chip_hwnum, con_id, flags) 117 + GPIO_LOOKUP_IDX(key, chip_hwnum, con_id, idx, flags) 118 118 119 119 where 120 120 121 - - chip_label is the label of the gpiod_chip instance providing the GPIO 122 - - chip_hwnum is the hardware number of the GPIO within the chip 121 + - key is either the label of the gpiod_chip instance providing the GPIO, or 122 + the GPIO line name 123 + - chip_hwnum is the hardware number of the GPIO within the chip, or U16_MAX 124 + to indicate that key is a GPIO line name 123 125 - con_id is the name of the GPIO function from the device point of view. It 124 126 can be NULL, in which case it will match any function. 125 127 - idx is the index of the GPIO within the function. ··· 137 135 138 136 In the future, these flags might be extended to support more properties. 139 137 140 - Note that GPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0. 138 + Note that: 139 + 1. GPIO line names are not guaranteed to be globally unique, so the first 140 + match found will be used. 141 + 2. GPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0. 141 142 142 143 A lookup table can then be defined as follows, with an empty entry defining its 143 144 end. The 'dev_id' field of the table is the identifier of the device that will
+15 -1
MAINTAINERS
··· 7283 7283 F: drivers/gpio/gpiolib-acpi.c 7284 7284 F: drivers/gpio/gpiolib-acpi.h 7285 7285 7286 + GPIO AGGREGATOR 7287 + M: Geert Uytterhoeven <geert+renesas@glider.be> 7288 + L: linux-gpio@vger.kernel.org 7289 + S: Supported 7290 + F: Documentation/admin-guide/gpio/gpio-aggregator.rst 7291 + F: drivers/gpio/gpio-aggregator.c 7292 + 7286 7293 GPIO IR Transmitter 7287 7294 M: Sean Young <sean@mess.org> 7288 7295 L: linux-media@vger.kernel.org ··· 7302 7295 S: Maintained 7303 7296 F: drivers/gpio/gpio-mockup.c 7304 7297 F: tools/testing/selftests/gpio/ 7298 + 7299 + GPIO REGMAP 7300 + R: Michael Walle <michael@walle.cc> 7301 + S: Maintained 7302 + F: drivers/gpio/gpio-regmap.c 7303 + F: include/linux/gpio/regmap.h 7305 7304 7306 7305 GPIO SUBSYSTEM 7307 7306 M: Linus Walleij <linus.walleij@linaro.org> ··· 16381 16368 16382 16369 SYNOPSYS DESIGNWARE APB GPIO DRIVER 16383 16370 M: Hoan Tran <hoan@os.amperecomputing.com> 16371 + M: Serge Semin <fancer.lancer@gmail.com> 16384 16372 L: linux-gpio@vger.kernel.org 16385 16373 S: Maintained 16386 - F: Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt 16374 + F: Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml 16387 16375 F: drivers/gpio/gpio-dwapb.c 16388 16376 16389 16377 SYNOPSYS DESIGNWARE AXI DMAC DRIVER
+20 -4
drivers/gpio/Kconfig
··· 73 73 depends on HAS_IOMEM # Only for IOMEM drivers 74 74 tristate 75 75 76 + config GPIO_REGMAP 77 + depends on REGMAP 78 + tristate 79 + 76 80 # put drivers in the right section, in alphabetical order 77 81 78 82 # This symbol is selected by both I2C and SPI expanders ··· 426 422 Say yes here to enable GPIO support for TI OMAP SoCs. 427 423 428 424 config GPIO_PL061 429 - bool "PrimeCell PL061 GPIO support" 425 + tristate "PrimeCell PL061 GPIO support" 430 426 depends on ARM_AMBA 431 427 select IRQ_DOMAIN 432 428 select GPIOLIB_IRQCHIP ··· 443 439 444 440 config GPIO_PXA 445 441 bool "PXA GPIO support" 446 - depends on ARCH_PXA || ARCH_MMP 442 + depends on ARCH_PXA || ARCH_MMP || COMPILE_TEST 447 443 help 448 444 Say yes here to support the PXA GPIO device 449 445 ··· 642 638 643 639 config GPIO_XGENE_SB 644 640 tristate "APM X-Gene GPIO standby controller support" 645 - depends on ARCH_XGENE && OF_GPIO 641 + depends on (ARCH_XGENE || COMPILE_TEST) 646 642 select GPIO_GENERIC 647 643 select GPIOLIB_IRQCHIP 648 644 select IRQ_DOMAIN_HIERARCHY ··· 956 952 957 953 config GPIO_PCA953X_IRQ 958 954 bool "Interrupt controller support for PCA953x" 959 - depends on GPIO_PCA953X=y 955 + depends on GPIO_PCA953X 960 956 select GPIOLIB_IRQCHIP 961 957 help 962 958 Say yes here to enable the pca953x to be used as an interrupt ··· 1544 1540 of the module parameters. 1545 1541 1546 1542 endmenu 1543 + 1544 + config GPIO_AGGREGATOR 1545 + tristate "GPIO Aggregator" 1546 + help 1547 + Say yes here to enable the GPIO Aggregator, which provides a way to 1548 + aggregate existing GPIO lines into a new virtual GPIO chip. 1549 + This can serve the following purposes: 1550 + - Assign permissions for a collection of GPIO lines to a user, 1551 + - Export a collection of GPIO lines to a virtual machine, 1552 + - Provide a generic driver for a GPIO-operated device in an 1553 + industrial control context, to be operated from userspace using 1554 + the GPIO chardev interface. 1547 1555 1548 1556 config GPIO_MOCKUP 1549 1557 tristate "GPIO Testing Driver"
+2
drivers/gpio/Makefile
··· 12 12 obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o 13 13 14 14 # Device drivers. Generally keep list sorted alphabetically 15 + obj-$(CONFIG_GPIO_REGMAP) += gpio-regmap.o 15 16 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o 16 17 17 18 # directly supported by gpio-generic ··· 26 25 obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o 27 26 obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o 28 27 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 28 + obj-$(CONFIG_GPIO_AGGREGATOR) += gpio-aggregator.o 29 29 obj-$(CONFIG_GPIO_ALTERA_A10SR) += gpio-altera-a10sr.o 30 30 obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o 31 31 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
+4
drivers/gpio/TODO
··· 99 99 In some cases it makes sense to create a GPIO chip from the local driver 100 100 for a few GPIOs. Those should stay where they are. 101 101 102 + At the same time it makes sense to get rid of code duplication in existing or 103 + new coming drivers. For example, gpio-ml-ioh should be incorporated into 104 + gpio-pch. In similar way gpio-intel-mid into gpio-pxa. 105 + 102 106 103 107 Generic MMIO GPIO 104 108
+568
drivers/gpio/gpio-aggregator.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // 3 + // GPIO Aggregator 4 + // 5 + // Copyright (C) 2019-2020 Glider bv 6 + 7 + #define DRV_NAME "gpio-aggregator" 8 + #define pr_fmt(fmt) DRV_NAME ": " fmt 9 + 10 + #include <linux/bitmap.h> 11 + #include <linux/bitops.h> 12 + #include <linux/ctype.h> 13 + #include <linux/gpio/consumer.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/gpio/machine.h> 16 + #include <linux/idr.h> 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/mutex.h> 20 + #include <linux/overflow.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/spinlock.h> 23 + #include <linux/string.h> 24 + 25 + 26 + /* 27 + * GPIO Aggregator sysfs interface 28 + */ 29 + 30 + struct gpio_aggregator { 31 + struct gpiod_lookup_table *lookups; 32 + struct platform_device *pdev; 33 + char args[]; 34 + }; 35 + 36 + static DEFINE_MUTEX(gpio_aggregator_lock); /* protects idr */ 37 + static DEFINE_IDR(gpio_aggregator_idr); 38 + 39 + static char *get_arg(char **args) 40 + { 41 + char *start = *args, *end; 42 + 43 + start = skip_spaces(start); 44 + if (!*start) 45 + return NULL; 46 + 47 + if (*start == '"') { 48 + /* Quoted arg */ 49 + end = strchr(++start, '"'); 50 + if (!end) 51 + return ERR_PTR(-EINVAL); 52 + } else { 53 + /* Unquoted arg */ 54 + for (end = start; *end && !isspace(*end); end++) ; 55 + } 56 + 57 + if (*end) 58 + *end++ = '\0'; 59 + 60 + *args = end; 61 + return start; 62 + } 63 + 64 + static bool isrange(const char *s) 65 + { 66 + size_t n; 67 + 68 + if (IS_ERR_OR_NULL(s)) 69 + return false; 70 + 71 + while (1) { 72 + n = strspn(s, "0123456789"); 73 + if (!n) 74 + return false; 75 + 76 + s += n; 77 + 78 + switch (*s++) { 79 + case '\0': 80 + return true; 81 + 82 + case '-': 83 + case ',': 84 + break; 85 + 86 + default: 87 + return false; 88 + } 89 + } 90 + } 91 + 92 + static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key, 93 + int hwnum, unsigned int *n) 94 + { 95 + struct gpiod_lookup_table *lookups; 96 + 97 + lookups = krealloc(aggr->lookups, struct_size(lookups, table, *n + 2), 98 + GFP_KERNEL); 99 + if (!lookups) 100 + return -ENOMEM; 101 + 102 + lookups->table[*n] = 103 + (struct gpiod_lookup)GPIO_LOOKUP_IDX(key, hwnum, NULL, *n, 0); 104 + 105 + (*n)++; 106 + memset(&lookups->table[*n], 0, sizeof(lookups->table[*n])); 107 + 108 + aggr->lookups = lookups; 109 + return 0; 110 + } 111 + 112 + static int aggr_parse(struct gpio_aggregator *aggr) 113 + { 114 + unsigned int first_index, last_index, i, n = 0; 115 + char *name, *offsets, *first, *last, *next; 116 + char *args = aggr->args; 117 + int error; 118 + 119 + for (name = get_arg(&args), offsets = get_arg(&args); name; 120 + offsets = get_arg(&args)) { 121 + if (IS_ERR(name)) { 122 + pr_err("Cannot get GPIO specifier: %pe\n", name); 123 + return PTR_ERR(name); 124 + } 125 + 126 + if (!isrange(offsets)) { 127 + /* Named GPIO line */ 128 + error = aggr_add_gpio(aggr, name, U16_MAX, &n); 129 + if (error) 130 + return error; 131 + 132 + name = offsets; 133 + continue; 134 + } 135 + 136 + /* GPIO chip + offset(s) */ 137 + for (first = offsets; *first; first = next) { 138 + next = strchrnul(first, ','); 139 + if (*next) 140 + *next++ = '\0'; 141 + 142 + last = strchr(first, '-'); 143 + if (last) 144 + *last++ = '\0'; 145 + 146 + if (kstrtouint(first, 10, &first_index)) { 147 + pr_err("Cannot parse GPIO index %s\n", first); 148 + return -EINVAL; 149 + } 150 + 151 + if (!last) { 152 + last_index = first_index; 153 + } else if (kstrtouint(last, 10, &last_index)) { 154 + pr_err("Cannot parse GPIO index %s\n", last); 155 + return -EINVAL; 156 + } 157 + 158 + for (i = first_index; i <= last_index; i++) { 159 + error = aggr_add_gpio(aggr, name, i, &n); 160 + if (error) 161 + return error; 162 + } 163 + } 164 + 165 + name = get_arg(&args); 166 + } 167 + 168 + if (!n) { 169 + pr_err("No GPIOs specified\n"); 170 + return -EINVAL; 171 + } 172 + 173 + return 0; 174 + } 175 + 176 + static ssize_t new_device_store(struct device_driver *driver, const char *buf, 177 + size_t count) 178 + { 179 + struct gpio_aggregator *aggr; 180 + struct platform_device *pdev; 181 + int res, id; 182 + 183 + /* kernfs guarantees string termination, so count + 1 is safe */ 184 + aggr = kzalloc(sizeof(*aggr) + count + 1, GFP_KERNEL); 185 + if (!aggr) 186 + return -ENOMEM; 187 + 188 + memcpy(aggr->args, buf, count + 1); 189 + 190 + aggr->lookups = kzalloc(struct_size(aggr->lookups, table, 1), 191 + GFP_KERNEL); 192 + if (!aggr->lookups) { 193 + res = -ENOMEM; 194 + goto free_ga; 195 + } 196 + 197 + mutex_lock(&gpio_aggregator_lock); 198 + id = idr_alloc(&gpio_aggregator_idr, aggr, 0, 0, GFP_KERNEL); 199 + mutex_unlock(&gpio_aggregator_lock); 200 + 201 + if (id < 0) { 202 + res = id; 203 + goto free_table; 204 + } 205 + 206 + aggr->lookups->dev_id = kasprintf(GFP_KERNEL, "%s.%d", DRV_NAME, id); 207 + if (!aggr->lookups->dev_id) { 208 + res = -ENOMEM; 209 + goto remove_idr; 210 + } 211 + 212 + res = aggr_parse(aggr); 213 + if (res) 214 + goto free_dev_id; 215 + 216 + gpiod_add_lookup_table(aggr->lookups); 217 + 218 + pdev = platform_device_register_simple(DRV_NAME, id, NULL, 0); 219 + if (IS_ERR(pdev)) { 220 + res = PTR_ERR(pdev); 221 + goto remove_table; 222 + } 223 + 224 + aggr->pdev = pdev; 225 + return count; 226 + 227 + remove_table: 228 + gpiod_remove_lookup_table(aggr->lookups); 229 + free_dev_id: 230 + kfree(aggr->lookups->dev_id); 231 + remove_idr: 232 + mutex_lock(&gpio_aggregator_lock); 233 + idr_remove(&gpio_aggregator_idr, id); 234 + mutex_unlock(&gpio_aggregator_lock); 235 + free_table: 236 + kfree(aggr->lookups); 237 + free_ga: 238 + kfree(aggr); 239 + return res; 240 + } 241 + 242 + static DRIVER_ATTR_WO(new_device); 243 + 244 + static void gpio_aggregator_free(struct gpio_aggregator *aggr) 245 + { 246 + platform_device_unregister(aggr->pdev); 247 + gpiod_remove_lookup_table(aggr->lookups); 248 + kfree(aggr->lookups->dev_id); 249 + kfree(aggr->lookups); 250 + kfree(aggr); 251 + } 252 + 253 + static ssize_t delete_device_store(struct device_driver *driver, 254 + const char *buf, size_t count) 255 + { 256 + struct gpio_aggregator *aggr; 257 + unsigned int id; 258 + int error; 259 + 260 + if (!str_has_prefix(buf, DRV_NAME ".")) 261 + return -EINVAL; 262 + 263 + error = kstrtouint(buf + strlen(DRV_NAME "."), 10, &id); 264 + if (error) 265 + return error; 266 + 267 + mutex_lock(&gpio_aggregator_lock); 268 + aggr = idr_remove(&gpio_aggregator_idr, id); 269 + mutex_unlock(&gpio_aggregator_lock); 270 + if (!aggr) 271 + return -ENOENT; 272 + 273 + gpio_aggregator_free(aggr); 274 + return count; 275 + } 276 + static DRIVER_ATTR_WO(delete_device); 277 + 278 + static struct attribute *gpio_aggregator_attrs[] = { 279 + &driver_attr_new_device.attr, 280 + &driver_attr_delete_device.attr, 281 + NULL, 282 + }; 283 + ATTRIBUTE_GROUPS(gpio_aggregator); 284 + 285 + static int __exit gpio_aggregator_idr_remove(int id, void *p, void *data) 286 + { 287 + gpio_aggregator_free(p); 288 + return 0; 289 + } 290 + 291 + static void __exit gpio_aggregator_remove_all(void) 292 + { 293 + mutex_lock(&gpio_aggregator_lock); 294 + idr_for_each(&gpio_aggregator_idr, gpio_aggregator_idr_remove, NULL); 295 + idr_destroy(&gpio_aggregator_idr); 296 + mutex_unlock(&gpio_aggregator_lock); 297 + } 298 + 299 + 300 + /* 301 + * GPIO Forwarder 302 + */ 303 + 304 + struct gpiochip_fwd { 305 + struct gpio_chip chip; 306 + struct gpio_desc **descs; 307 + union { 308 + struct mutex mlock; /* protects tmp[] if can_sleep */ 309 + spinlock_t slock; /* protects tmp[] if !can_sleep */ 310 + }; 311 + unsigned long tmp[]; /* values and descs for multiple ops */ 312 + }; 313 + 314 + static int gpio_fwd_get_direction(struct gpio_chip *chip, unsigned int offset) 315 + { 316 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 317 + 318 + return gpiod_get_direction(fwd->descs[offset]); 319 + } 320 + 321 + static int gpio_fwd_direction_input(struct gpio_chip *chip, unsigned int offset) 322 + { 323 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 324 + 325 + return gpiod_direction_input(fwd->descs[offset]); 326 + } 327 + 328 + static int gpio_fwd_direction_output(struct gpio_chip *chip, 329 + unsigned int offset, int value) 330 + { 331 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 332 + 333 + return gpiod_direction_output(fwd->descs[offset], value); 334 + } 335 + 336 + static int gpio_fwd_get(struct gpio_chip *chip, unsigned int offset) 337 + { 338 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 339 + 340 + return gpiod_get_value(fwd->descs[offset]); 341 + } 342 + 343 + static int gpio_fwd_get_multiple(struct gpio_chip *chip, unsigned long *mask, 344 + unsigned long *bits) 345 + { 346 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 347 + unsigned long *values, flags = 0; 348 + struct gpio_desc **descs; 349 + unsigned int i, j = 0; 350 + int error; 351 + 352 + if (chip->can_sleep) 353 + mutex_lock(&fwd->mlock); 354 + else 355 + spin_lock_irqsave(&fwd->slock, flags); 356 + 357 + /* Both values bitmap and desc pointers are stored in tmp[] */ 358 + values = &fwd->tmp[0]; 359 + descs = (void *)&fwd->tmp[BITS_TO_LONGS(fwd->chip.ngpio)]; 360 + 361 + bitmap_clear(values, 0, fwd->chip.ngpio); 362 + for_each_set_bit(i, mask, fwd->chip.ngpio) 363 + descs[j++] = fwd->descs[i]; 364 + 365 + error = gpiod_get_array_value(j, descs, NULL, values); 366 + if (!error) { 367 + j = 0; 368 + for_each_set_bit(i, mask, fwd->chip.ngpio) 369 + __assign_bit(i, bits, test_bit(j++, values)); 370 + } 371 + 372 + if (chip->can_sleep) 373 + mutex_unlock(&fwd->mlock); 374 + else 375 + spin_unlock_irqrestore(&fwd->slock, flags); 376 + 377 + return error; 378 + } 379 + 380 + static void gpio_fwd_set(struct gpio_chip *chip, unsigned int offset, int value) 381 + { 382 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 383 + 384 + gpiod_set_value(fwd->descs[offset], value); 385 + } 386 + 387 + static void gpio_fwd_set_multiple(struct gpio_chip *chip, unsigned long *mask, 388 + unsigned long *bits) 389 + { 390 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 391 + unsigned long *values, flags = 0; 392 + struct gpio_desc **descs; 393 + unsigned int i, j = 0; 394 + 395 + if (chip->can_sleep) 396 + mutex_lock(&fwd->mlock); 397 + else 398 + spin_lock_irqsave(&fwd->slock, flags); 399 + 400 + /* Both values bitmap and desc pointers are stored in tmp[] */ 401 + values = &fwd->tmp[0]; 402 + descs = (void *)&fwd->tmp[BITS_TO_LONGS(fwd->chip.ngpio)]; 403 + 404 + for_each_set_bit(i, mask, fwd->chip.ngpio) { 405 + __assign_bit(j, values, test_bit(i, bits)); 406 + descs[j++] = fwd->descs[i]; 407 + } 408 + 409 + gpiod_set_array_value(j, descs, NULL, values); 410 + 411 + if (chip->can_sleep) 412 + mutex_unlock(&fwd->mlock); 413 + else 414 + spin_unlock_irqrestore(&fwd->slock, flags); 415 + } 416 + 417 + static int gpio_fwd_set_config(struct gpio_chip *chip, unsigned int offset, 418 + unsigned long config) 419 + { 420 + struct gpiochip_fwd *fwd = gpiochip_get_data(chip); 421 + 422 + return gpiod_set_config(fwd->descs[offset], config); 423 + } 424 + 425 + /** 426 + * gpiochip_fwd_create() - Create a new GPIO forwarder 427 + * @dev: Parent device pointer 428 + * @ngpios: Number of GPIOs in the forwarder. 429 + * @descs: Array containing the GPIO descriptors to forward to. 430 + * This array must contain @ngpios entries, and must not be deallocated 431 + * before the forwarder has been destroyed again. 432 + * 433 + * This function creates a new gpiochip, which forwards all GPIO operations to 434 + * the passed GPIO descriptors. 435 + * 436 + * Return: An opaque object pointer, or an ERR_PTR()-encoded negative error 437 + * code on failure. 438 + */ 439 + static struct gpiochip_fwd *gpiochip_fwd_create(struct device *dev, 440 + unsigned int ngpios, 441 + struct gpio_desc *descs[]) 442 + { 443 + const char *label = dev_name(dev); 444 + struct gpiochip_fwd *fwd; 445 + struct gpio_chip *chip; 446 + unsigned int i; 447 + int error; 448 + 449 + fwd = devm_kzalloc(dev, struct_size(fwd, tmp, 450 + BITS_TO_LONGS(ngpios) + ngpios), GFP_KERNEL); 451 + if (!fwd) 452 + return ERR_PTR(-ENOMEM); 453 + 454 + chip = &fwd->chip; 455 + 456 + /* 457 + * If any of the GPIO lines are sleeping, then the entire forwarder 458 + * will be sleeping. 459 + * If any of the chips support .set_config(), then the forwarder will 460 + * support setting configs. 461 + */ 462 + for (i = 0; i < ngpios; i++) { 463 + struct gpio_chip *parent = gpiod_to_chip(descs[i]); 464 + 465 + dev_dbg(dev, "%u => gpio-%d\n", i, desc_to_gpio(descs[i])); 466 + 467 + if (gpiod_cansleep(descs[i])) 468 + chip->can_sleep = true; 469 + if (parent && parent->set_config) 470 + chip->set_config = gpio_fwd_set_config; 471 + } 472 + 473 + chip->label = label; 474 + chip->parent = dev; 475 + chip->owner = THIS_MODULE; 476 + chip->get_direction = gpio_fwd_get_direction; 477 + chip->direction_input = gpio_fwd_direction_input; 478 + chip->direction_output = gpio_fwd_direction_output; 479 + chip->get = gpio_fwd_get; 480 + chip->get_multiple = gpio_fwd_get_multiple; 481 + chip->set = gpio_fwd_set; 482 + chip->set_multiple = gpio_fwd_set_multiple; 483 + chip->base = -1; 484 + chip->ngpio = ngpios; 485 + fwd->descs = descs; 486 + 487 + if (chip->can_sleep) 488 + mutex_init(&fwd->mlock); 489 + else 490 + spin_lock_init(&fwd->slock); 491 + 492 + error = devm_gpiochip_add_data(dev, chip, fwd); 493 + if (error) 494 + return ERR_PTR(error); 495 + 496 + return fwd; 497 + } 498 + 499 + 500 + /* 501 + * GPIO Aggregator platform device 502 + */ 503 + 504 + static int gpio_aggregator_probe(struct platform_device *pdev) 505 + { 506 + struct device *dev = &pdev->dev; 507 + struct gpio_desc **descs; 508 + struct gpiochip_fwd *fwd; 509 + int i, n; 510 + 511 + n = gpiod_count(dev, NULL); 512 + if (n < 0) 513 + return n; 514 + 515 + descs = devm_kmalloc_array(dev, n, sizeof(*descs), GFP_KERNEL); 516 + if (!descs) 517 + return -ENOMEM; 518 + 519 + for (i = 0; i < n; i++) { 520 + descs[i] = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS); 521 + if (IS_ERR(descs[i])) 522 + return PTR_ERR(descs[i]); 523 + } 524 + 525 + fwd = gpiochip_fwd_create(dev, n, descs); 526 + if (IS_ERR(fwd)) 527 + return PTR_ERR(fwd); 528 + 529 + platform_set_drvdata(pdev, fwd); 530 + return 0; 531 + } 532 + 533 + #ifdef CONFIG_OF 534 + static const struct of_device_id gpio_aggregator_dt_ids[] = { 535 + /* 536 + * Add GPIO-operated devices controlled from userspace below, 537 + * or use "driver_override" in sysfs 538 + */ 539 + {}, 540 + }; 541 + MODULE_DEVICE_TABLE(of, gpio_aggregator_dt_ids); 542 + #endif 543 + 544 + static struct platform_driver gpio_aggregator_driver = { 545 + .probe = gpio_aggregator_probe, 546 + .driver = { 547 + .name = DRV_NAME, 548 + .groups = gpio_aggregator_groups, 549 + .of_match_table = of_match_ptr(gpio_aggregator_dt_ids), 550 + }, 551 + }; 552 + 553 + static int __init gpio_aggregator_init(void) 554 + { 555 + return platform_driver_register(&gpio_aggregator_driver); 556 + } 557 + module_init(gpio_aggregator_init); 558 + 559 + static void __exit gpio_aggregator_exit(void) 560 + { 561 + gpio_aggregator_remove_all(); 562 + platform_driver_unregister(&gpio_aggregator_driver); 563 + } 564 + module_exit(gpio_aggregator_exit); 565 + 566 + MODULE_AUTHOR("Geert Uytterhoeven <geert+renesas@glider.be>"); 567 + MODULE_DESCRIPTION("GPIO Aggregator"); 568 + MODULE_LICENSE("GPL v2");
+111 -137
drivers/gpio/gpio-dwapb.c
··· 49 49 #define GPIO_EXT_PORTC 0x58 50 50 #define GPIO_EXT_PORTD 0x5c 51 51 52 + #define DWAPB_DRIVER_NAME "gpio-dwapb" 52 53 #define DWAPB_MAX_PORTS 4 54 + 53 55 #define GPIO_EXT_PORT_STRIDE 0x04 /* register stride 32 bits */ 54 56 #define GPIO_SWPORT_DR_STRIDE 0x0c /* register stride 3*32 bits */ 55 57 #define GPIO_SWPORT_DDR_STRIDE 0x0c /* register stride 3*32 bits */ ··· 63 61 #define GPIO_INT_POLARITY_V2 0x38 64 62 #define GPIO_INTSTATUS_V2 0x3c 65 63 #define GPIO_PORTA_EOI_V2 0x40 64 + 65 + #define DWAPB_NR_CLOCKS 2 66 66 67 67 struct dwapb_gpio; 68 68 ··· 101 97 struct irq_domain *domain; 102 98 unsigned int flags; 103 99 struct reset_control *rst; 104 - struct clk *clk; 100 + struct clk_bulk_data clks[DWAPB_NR_CLOCKS]; 105 101 }; 106 102 107 103 static inline u32 gpio_reg_v2_convert(unsigned int offset) ··· 193 189 194 190 static u32 dwapb_do_irq(struct dwapb_gpio *gpio) 195 191 { 196 - u32 irq_status = dwapb_read(gpio, GPIO_INTSTATUS); 197 - u32 ret = irq_status; 192 + unsigned long irq_status; 193 + irq_hw_number_t hwirq; 198 194 199 - while (irq_status) { 200 - int hwirq = fls(irq_status) - 1; 195 + irq_status = dwapb_read(gpio, GPIO_INTSTATUS); 196 + for_each_set_bit(hwirq, &irq_status, 32) { 201 197 int gpio_irq = irq_find_mapping(gpio->domain, hwirq); 198 + u32 irq_type = irq_get_trigger_type(gpio_irq); 202 199 203 200 generic_handle_irq(gpio_irq); 204 - irq_status &= ~BIT(hwirq); 205 201 206 - if ((irq_get_trigger_type(gpio_irq) & IRQ_TYPE_SENSE_MASK) 207 - == IRQ_TYPE_EDGE_BOTH) 202 + if ((irq_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) 208 203 dwapb_toggle_trigger(gpio, hwirq); 209 204 } 210 205 211 - return ret; 206 + return irq_status; 212 207 } 213 208 214 209 static void dwapb_irq_handler(struct irq_desc *desc) ··· 215 212 struct dwapb_gpio *gpio = irq_desc_get_handler_data(desc); 216 213 struct irq_chip *chip = irq_desc_get_chip(desc); 217 214 215 + chained_irq_enter(chip, desc); 218 216 dwapb_do_irq(gpio); 219 - 220 - if (chip->irq_eoi) 221 - chip->irq_eoi(irq_desc_get_irq_data(desc)); 217 + chained_irq_exit(chip, desc); 222 218 } 223 219 224 220 static void dwapb_irq_enable(struct irq_data *d) ··· 230 228 231 229 spin_lock_irqsave(&gc->bgpio_lock, flags); 232 230 val = dwapb_read(gpio, GPIO_INTEN); 233 - val |= BIT(d->hwirq); 231 + val |= BIT(irqd_to_hwirq(d)); 234 232 dwapb_write(gpio, GPIO_INTEN, val); 235 233 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 236 234 } ··· 245 243 246 244 spin_lock_irqsave(&gc->bgpio_lock, flags); 247 245 val = dwapb_read(gpio, GPIO_INTEN); 248 - val &= ~BIT(d->hwirq); 246 + val &= ~BIT(irqd_to_hwirq(d)); 249 247 dwapb_write(gpio, GPIO_INTEN, val); 250 248 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 251 - } 252 - 253 - static int dwapb_irq_reqres(struct irq_data *d) 254 - { 255 - struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 256 - struct dwapb_gpio *gpio = igc->private; 257 - struct gpio_chip *gc = &gpio->ports[0].gc; 258 - int ret; 259 - 260 - ret = gpiochip_lock_as_irq(gc, irqd_to_hwirq(d)); 261 - if (ret) { 262 - dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", 263 - irqd_to_hwirq(d)); 264 - return ret; 265 - } 266 - return 0; 267 - } 268 - 269 - static void dwapb_irq_relres(struct irq_data *d) 270 - { 271 - struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 272 - struct dwapb_gpio *gpio = igc->private; 273 - struct gpio_chip *gc = &gpio->ports[0].gc; 274 - 275 - gpiochip_unlock_as_irq(gc, irqd_to_hwirq(d)); 276 249 } 277 250 278 251 static int dwapb_irq_set_type(struct irq_data *d, u32 type) ··· 255 278 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 256 279 struct dwapb_gpio *gpio = igc->private; 257 280 struct gpio_chip *gc = &gpio->ports[0].gc; 258 - int bit = d->hwirq; 281 + irq_hw_number_t bit = irqd_to_hwirq(d); 259 282 unsigned long level, polarity, flags; 260 283 261 - if (type & ~(IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | 262 - IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 284 + if (type & ~IRQ_TYPE_SENSE_MASK) 263 285 return -EINVAL; 264 286 265 287 spin_lock_irqsave(&gc->bgpio_lock, flags); ··· 304 328 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 305 329 struct dwapb_gpio *gpio = igc->private; 306 330 struct dwapb_context *ctx = gpio->ports[0].ctx; 331 + irq_hw_number_t bit = irqd_to_hwirq(d); 307 332 308 333 if (enable) 309 - ctx->wake_en |= BIT(d->hwirq); 334 + ctx->wake_en |= BIT(bit); 310 335 else 311 - ctx->wake_en &= ~BIT(d->hwirq); 336 + ctx->wake_en &= ~BIT(bit); 312 337 313 338 return 0; 314 339 } ··· 327 350 328 351 val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); 329 352 if (debounce) 330 - dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb | mask); 353 + val_deb |= mask; 331 354 else 332 - dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); 355 + val_deb &= ~mask; 356 + dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb); 333 357 334 358 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 335 359 ··· 351 373 352 374 static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id) 353 375 { 354 - u32 worked; 355 - struct dwapb_gpio *gpio = dev_id; 356 - 357 - worked = dwapb_do_irq(gpio); 358 - 359 - return worked ? IRQ_HANDLED : IRQ_NONE; 376 + return IRQ_RETVAL(dwapb_do_irq(dev_id)); 360 377 } 361 378 362 379 static void dwapb_configure_irqs(struct dwapb_gpio *gpio, ··· 361 388 struct gpio_chip *gc = &port->gc; 362 389 struct fwnode_handle *fwnode = pp->fwnode; 363 390 struct irq_chip_generic *irq_gc = NULL; 364 - unsigned int hwirq, ngpio = gc->ngpio; 391 + unsigned int ngpio = gc->ngpio; 365 392 struct irq_chip_type *ct; 393 + irq_hw_number_t hwirq; 366 394 int err, i; 395 + 396 + if (memchr_inv(pp->irq, 0, sizeof(pp->irq)) == NULL) { 397 + dev_warn(gpio->dev, "no IRQ for port%d\n", pp->idx); 398 + return; 399 + } 367 400 368 401 gpio->domain = irq_domain_create_linear(fwnode, ngpio, 369 402 &irq_generic_chip_ops, gpio); ··· 377 398 return; 378 399 379 400 err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 2, 380 - "gpio-dwapb", handle_level_irq, 401 + DWAPB_DRIVER_NAME, handle_bad_irq, 381 402 IRQ_NOREQUEST, 0, 382 403 IRQ_GC_INIT_NESTED_LOCK); 383 404 if (err) { ··· 405 426 ct->chip.irq_set_type = dwapb_irq_set_type; 406 427 ct->chip.irq_enable = dwapb_irq_enable; 407 428 ct->chip.irq_disable = dwapb_irq_disable; 408 - ct->chip.irq_request_resources = dwapb_irq_reqres; 409 - ct->chip.irq_release_resources = dwapb_irq_relres; 410 429 #ifdef CONFIG_PM_SLEEP 411 430 ct->chip.irq_set_wake = dwapb_irq_set_wake; 412 431 #endif ··· 414 437 } 415 438 416 439 irq_gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK; 440 + irq_gc->chip_types[0].handler = handle_level_irq; 417 441 irq_gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH; 418 442 irq_gc->chip_types[1].handler = handle_edge_irq; 419 443 ··· 422 444 int i; 423 445 424 446 for (i = 0; i < pp->ngpio; i++) { 425 - if (pp->irq[i] >= 0) 447 + if (pp->irq[i]) 426 448 irq_set_chained_handler_and_data(pp->irq[i], 427 449 dwapb_irq_handler, gpio); 428 450 } ··· 433 455 */ 434 456 err = devm_request_irq(gpio->dev, pp->irq[0], 435 457 dwapb_irq_handler_mfd, 436 - IRQF_SHARED, "gpio-dwapb-mfd", gpio); 458 + IRQF_SHARED, DWAPB_DRIVER_NAME, gpio); 437 459 if (err) { 438 460 dev_err(gpio->dev, "error requesting IRQ\n"); 439 461 irq_domain_remove(gpio->domain); ··· 442 464 } 443 465 } 444 466 445 - for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 467 + for (hwirq = 0; hwirq < ngpio; hwirq++) 446 468 irq_create_mapping(gpio->domain, hwirq); 447 469 448 470 port->gc.to_irq = dwapb_gpio_to_irq; ··· 458 480 if (!gpio->domain) 459 481 return; 460 482 461 - for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 483 + for (hwirq = 0; hwirq < ngpio; hwirq++) 462 484 irq_dispose_mapping(irq_find_mapping(gpio->domain, hwirq)); 463 485 464 486 irq_domain_remove(gpio->domain); ··· 483 505 return -ENOMEM; 484 506 #endif 485 507 486 - dat = gpio->regs + GPIO_EXT_PORTA + (pp->idx * GPIO_EXT_PORT_STRIDE); 487 - set = gpio->regs + GPIO_SWPORTA_DR + (pp->idx * GPIO_SWPORT_DR_STRIDE); 488 - dirout = gpio->regs + GPIO_SWPORTA_DDR + 489 - (pp->idx * GPIO_SWPORT_DDR_STRIDE); 508 + dat = gpio->regs + GPIO_EXT_PORTA + pp->idx * GPIO_EXT_PORT_STRIDE; 509 + set = gpio->regs + GPIO_SWPORTA_DR + pp->idx * GPIO_SWPORT_DR_STRIDE; 510 + dirout = gpio->regs + GPIO_SWPORTA_DDR + pp->idx * GPIO_SWPORT_DDR_STRIDE; 490 511 491 512 /* This registers 32 GPIO lines per port */ 492 513 err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, ··· 506 529 if (pp->idx == 0) 507 530 port->gc.set_config = dwapb_gpio_set_config; 508 531 509 - if (pp->has_irq) 532 + /* Only port A can provide interrupts in all configurations of the IP */ 533 + if (pp->idx == 0) 510 534 dwapb_configure_irqs(gpio, port, pp); 511 535 512 536 err = gpiochip_add_data(&port->gc, port); 513 - if (err) 537 + if (err) { 514 538 dev_err(gpio->dev, "failed to register gpiochip for port%d\n", 515 539 port->idx); 516 - else 517 - port->is_registered = true; 540 + return err; 541 + } 518 542 519 543 /* Add GPIO-signaled ACPI event support */ 520 - if (pp->has_irq) 521 - acpi_gpiochip_request_interrupts(&port->gc); 544 + acpi_gpiochip_request_interrupts(&port->gc); 522 545 523 - return err; 546 + port->is_registered = true; 547 + 548 + return 0; 524 549 } 525 550 526 551 static void dwapb_gpio_unregister(struct dwapb_gpio *gpio) 527 552 { 528 553 unsigned int m; 529 554 530 - for (m = 0; m < gpio->nr_ports; ++m) 531 - if (gpio->ports[m].is_registered) 532 - gpiochip_remove(&gpio->ports[m].gc); 555 + for (m = 0; m < gpio->nr_ports; ++m) { 556 + struct dwapb_gpio_port *port = &gpio->ports[m]; 557 + 558 + if (!port->is_registered) 559 + continue; 560 + 561 + acpi_gpiochip_free_interrupts(&port->gc); 562 + gpiochip_remove(&port->gc); 563 + } 533 564 } 534 565 535 - static struct dwapb_platform_data * 536 - dwapb_gpio_get_pdata(struct device *dev) 566 + static void dwapb_get_irq(struct device *dev, struct fwnode_handle *fwnode, 567 + struct dwapb_port_property *pp) 568 + { 569 + struct device_node *np = NULL; 570 + int irq = -ENXIO, j; 571 + 572 + if (fwnode_property_read_bool(fwnode, "interrupt-controller")) 573 + np = to_of_node(fwnode); 574 + 575 + for (j = 0; j < pp->ngpio; j++) { 576 + if (np) 577 + irq = of_irq_get(np, j); 578 + else if (has_acpi_companion(dev)) 579 + irq = platform_get_irq_optional(to_platform_device(dev), j); 580 + if (irq > 0) 581 + pp->irq[j] = irq; 582 + } 583 + } 584 + 585 + static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) 537 586 { 538 587 struct fwnode_handle *fwnode; 539 588 struct dwapb_platform_data *pdata; 540 589 struct dwapb_port_property *pp; 541 590 int nports; 542 - int i, j; 591 + int i; 543 592 544 593 nports = device_get_child_node_count(dev); 545 594 if (nports == 0) ··· 583 580 584 581 i = 0; 585 582 device_for_each_child_node(dev, fwnode) { 586 - struct device_node *np = NULL; 587 - 588 583 pp = &pdata->properties[i++]; 589 584 pp->fwnode = fwnode; 590 585 ··· 594 593 return ERR_PTR(-EINVAL); 595 594 } 596 595 597 - if (fwnode_property_read_u32(fwnode, "snps,nr-gpios", 598 - &pp->ngpio)) { 596 + if (fwnode_property_read_u32(fwnode, "snps,nr-gpios", &pp->ngpio)) { 599 597 dev_info(dev, 600 598 "failed to get number of gpios for port%d\n", 601 599 i); ··· 608 608 * Only port A can provide interrupts in all configurations of 609 609 * the IP. 610 610 */ 611 - if (pp->idx != 0) 612 - continue; 613 - 614 - if (dev->of_node && fwnode_property_read_bool(fwnode, 615 - "interrupt-controller")) { 616 - np = to_of_node(fwnode); 617 - } 618 - 619 - for (j = 0; j < pp->ngpio; j++) { 620 - pp->irq[j] = -ENXIO; 621 - 622 - if (np) 623 - pp->irq[j] = of_irq_get(np, j); 624 - else if (has_acpi_companion(dev)) 625 - pp->irq[j] = platform_get_irq(to_platform_device(dev), j); 626 - 627 - if (pp->irq[j] >= 0) 628 - pp->has_irq = true; 629 - } 630 - 631 - if (!pp->has_irq) 632 - dev_warn(dev, "no irq for port%d\n", pp->idx); 611 + if (pp->idx == 0) 612 + dwapb_get_irq(dev, fwnode, pp); 633 613 } 634 614 635 615 return pdata; ··· 669 689 if (IS_ERR(gpio->regs)) 670 690 return PTR_ERR(gpio->regs); 671 691 672 - /* Optional bus clock */ 673 - gpio->clk = devm_clk_get(&pdev->dev, "bus"); 674 - if (!IS_ERR(gpio->clk)) { 675 - err = clk_prepare_enable(gpio->clk); 676 - if (err) { 677 - dev_info(&pdev->dev, "Cannot enable clock\n"); 678 - return err; 679 - } 692 + /* Optional bus and debounce clocks */ 693 + gpio->clks[0].id = "bus"; 694 + gpio->clks[1].id = "db"; 695 + err = devm_clk_bulk_get_optional(&pdev->dev, DWAPB_NR_CLOCKS, 696 + gpio->clks); 697 + if (err) { 698 + dev_err(&pdev->dev, "Cannot get APB/Debounce clocks\n"); 699 + return err; 680 700 } 681 701 682 - gpio->flags = 0; 683 - if (dev->of_node) { 684 - gpio->flags = (uintptr_t)of_device_get_match_data(dev); 685 - } else if (has_acpi_companion(dev)) { 686 - const struct acpi_device_id *acpi_id; 687 - 688 - acpi_id = acpi_match_device(dwapb_acpi_match, dev); 689 - if (acpi_id) { 690 - if (acpi_id->driver_data) 691 - gpio->flags = acpi_id->driver_data; 692 - } 702 + err = clk_bulk_prepare_enable(DWAPB_NR_CLOCKS, gpio->clks); 703 + if (err) { 704 + dev_err(&pdev->dev, "Cannot enable APB/Debounce clocks\n"); 705 + return err; 693 706 } 707 + 708 + gpio->flags = (uintptr_t)device_get_match_data(dev); 694 709 695 710 for (i = 0; i < gpio->nr_ports; i++) { 696 711 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); ··· 699 724 out_unregister: 700 725 dwapb_gpio_unregister(gpio); 701 726 dwapb_irq_teardown(gpio); 702 - clk_disable_unprepare(gpio->clk); 727 + clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks); 703 728 704 729 return err; 705 730 } ··· 711 736 dwapb_gpio_unregister(gpio); 712 737 dwapb_irq_teardown(gpio); 713 738 reset_control_assert(gpio->rst); 714 - clk_disable_unprepare(gpio->clk); 739 + clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks); 715 740 716 741 return 0; 717 742 } ··· 729 754 unsigned int offset; 730 755 unsigned int idx = gpio->ports[i].idx; 731 756 struct dwapb_context *ctx = gpio->ports[i].ctx; 732 - 733 - BUG_ON(!ctx); 734 757 735 758 offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE; 736 759 ctx->dir = dwapb_read(gpio, offset); ··· 748 775 ctx->int_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); 749 776 750 777 /* Mask out interrupts */ 751 - dwapb_write(gpio, GPIO_INTMASK, 752 - 0xffffffff & ~ctx->wake_en); 778 + dwapb_write(gpio, GPIO_INTMASK, ~ctx->wake_en); 753 779 } 754 780 } 755 781 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 756 782 757 - clk_disable_unprepare(gpio->clk); 783 + clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks); 758 784 759 785 return 0; 760 786 } ··· 763 791 struct dwapb_gpio *gpio = dev_get_drvdata(dev); 764 792 struct gpio_chip *gc = &gpio->ports[0].gc; 765 793 unsigned long flags; 766 - int i; 794 + int i, err; 767 795 768 - if (!IS_ERR(gpio->clk)) 769 - clk_prepare_enable(gpio->clk); 796 + err = clk_bulk_prepare_enable(DWAPB_NR_CLOCKS, gpio->clks); 797 + if (err) { 798 + dev_err(gpio->dev, "Cannot reenable APB/Debounce clocks\n"); 799 + return err; 800 + } 770 801 771 802 spin_lock_irqsave(&gc->bgpio_lock, flags); 772 803 for (i = 0; i < gpio->nr_ports; i++) { 773 804 unsigned int offset; 774 805 unsigned int idx = gpio->ports[i].idx; 775 806 struct dwapb_context *ctx = gpio->ports[i].ctx; 776 - 777 - BUG_ON(!ctx); 778 807 779 808 offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE; 780 809 dwapb_write(gpio, offset, ctx->data); ··· 809 836 810 837 static struct platform_driver dwapb_gpio_driver = { 811 838 .driver = { 812 - .name = "gpio-dwapb", 839 + .name = DWAPB_DRIVER_NAME, 813 840 .pm = &dwapb_gpio_pm_ops, 814 - .of_match_table = of_match_ptr(dwapb_of_match), 815 - .acpi_match_table = ACPI_PTR(dwapb_acpi_match), 841 + .of_match_table = dwapb_of_match, 842 + .acpi_match_table = dwapb_acpi_match, 816 843 }, 817 844 .probe = dwapb_gpio_probe, 818 845 .remove = dwapb_gpio_remove, ··· 823 850 MODULE_LICENSE("GPL"); 824 851 MODULE_AUTHOR("Jamie Iles"); 825 852 MODULE_DESCRIPTION("Synopsys DesignWare APB GPIO driver"); 853 + MODULE_ALIAS("platform:" DWAPB_DRIVER_NAME);
+28 -1
drivers/gpio/gpio-f7188x.c
··· 36 36 #define SIO_F71889A_ID 0x1005 /* F71889A chipset ID */ 37 37 #define SIO_F81866_ID 0x1010 /* F81866 chipset ID */ 38 38 #define SIO_F81804_ID 0x1502 /* F81804 chipset ID, same for f81966 */ 39 + #define SIO_F81865_ID 0x0704 /* F81865 chipset ID */ 39 40 40 41 41 - enum chips { f71869, f71869a, f71882fg, f71889a, f71889f, f81866, f81804 }; 42 + enum chips { 43 + f71869, 44 + f71869a, 45 + f71882fg, 46 + f71889a, 47 + f71889f, 48 + f81866, 49 + f81804, 50 + f81865, 51 + }; 42 52 43 53 static const char * const f7188x_names[] = { 44 54 "f71869", ··· 58 48 "f71889f", 59 49 "f81866", 60 50 "f81804", 51 + "f81865", 61 52 }; 62 53 63 54 struct f7188x_sio { ··· 244 233 F7188X_GPIO_BANK(90, 8, 0x98), 245 234 }; 246 235 236 + static struct f7188x_gpio_bank f81865_gpio_bank[] = { 237 + F7188X_GPIO_BANK(0, 8, 0xF0), 238 + F7188X_GPIO_BANK(10, 8, 0xE0), 239 + F7188X_GPIO_BANK(20, 8, 0xD0), 240 + F7188X_GPIO_BANK(30, 8, 0xC0), 241 + F7188X_GPIO_BANK(40, 8, 0xB0), 242 + F7188X_GPIO_BANK(50, 8, 0xA0), 243 + F7188X_GPIO_BANK(60, 5, 0x90), 244 + }; 247 245 248 246 static int f7188x_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 249 247 { ··· 445 425 data->nr_bank = ARRAY_SIZE(f81804_gpio_bank); 446 426 data->bank = f81804_gpio_bank; 447 427 break; 428 + case f81865: 429 + data->nr_bank = ARRAY_SIZE(f81865_gpio_bank); 430 + data->bank = f81865_gpio_bank; 431 + break; 448 432 default: 449 433 return -ENODEV; 450 434 } ··· 513 489 break; 514 490 case SIO_F81804_ID: 515 491 sio->type = f81804; 492 + break; 493 + case SIO_F81865_ID: 494 + sio->type = f81865; 516 495 break; 517 496 default: 518 497 pr_info(DRVNAME ": Unsupported Fintek device 0x%04x\n", devid);
+1 -1
drivers/gpio/gpio-ftgpio010.c
··· 193 193 if (val == deb_div) { 194 194 /* 195 195 * The debounce timer happens to already be set to the 196 - * desireable value, what a coincidence! We can just enable 196 + * desirable value, what a coincidence! We can just enable 197 197 * debounce on this GPIO line and return. This happens more 198 198 * often than you think, for example when all GPIO keys 199 199 * on a system are requesting the same debounce interval.
+1 -1
drivers/gpio/gpio-ich.c
··· 89 89 struct device *dev; 90 90 struct gpio_chip chip; 91 91 struct resource *gpio_base; /* GPIO IO base */ 92 - struct resource *pm_base; /* Power Mangagment IO base */ 92 + struct resource *pm_base; /* Power Management IO base */ 93 93 struct ichx_desc *desc; /* Pointer to chipset-specific description */ 94 94 u32 orig_gpio_ctrl; /* Orig CTRL value, used to restore on exit */ 95 95 u8 use_gpio; /* Which GPIO groups are usable */
+5 -7
drivers/gpio/gpio-max730x.c
··· 47 47 48 48 static int max7301_direction_input(struct gpio_chip *chip, unsigned offset) 49 49 { 50 - struct max7301 *ts = gpiochip_get_data(chip); 50 + struct max7301 *ts = container_of(chip, struct max7301, chip); 51 51 u8 *config; 52 52 u8 offset_bits, pin_config; 53 53 int ret; ··· 89 89 static int max7301_direction_output(struct gpio_chip *chip, unsigned offset, 90 90 int value) 91 91 { 92 - struct max7301 *ts = gpiochip_get_data(chip); 92 + struct max7301 *ts = container_of(chip, struct max7301, chip); 93 93 u8 *config; 94 94 u8 offset_bits; 95 95 int ret; ··· 189 189 ts->chip.parent = dev; 190 190 ts->chip.owner = THIS_MODULE; 191 191 192 - ret = gpiochip_add_data(&ts->chip, ts); 193 - if (ret) 194 - goto exit_destroy; 195 - 196 192 /* 197 193 * initialize pullups according to platform data and cache the 198 194 * register values for later use. ··· 210 214 } 211 215 } 212 216 213 - return ret; 217 + ret = gpiochip_add_data(&ts->chip, ts); 218 + if (!ret) 219 + return ret; 214 220 215 221 exit_destroy: 216 222 mutex_destroy(&ts->lock);
+12 -16
drivers/gpio/gpio-mb86s7x.c
··· 145 145 146 146 for (index = 0;; index++) { 147 147 irq = platform_get_irq(to_platform_device(gc->parent), index); 148 - if (irq <= 0) 148 + if (irq < 0) 149 + return irq; 150 + if (irq == 0) 149 151 break; 150 152 if (irq_get_irq_data(irq)->hwirq == offset) 151 153 return irq; ··· 170 168 if (IS_ERR(gchip->base)) 171 169 return PTR_ERR(gchip->base); 172 170 173 - if (!has_acpi_companion(&pdev->dev)) { 174 - gchip->clk = devm_clk_get(&pdev->dev, NULL); 175 - if (IS_ERR(gchip->clk)) 176 - return PTR_ERR(gchip->clk); 171 + gchip->clk = devm_clk_get_optional(&pdev->dev, NULL); 172 + if (IS_ERR(gchip->clk)) 173 + return PTR_ERR(gchip->clk); 177 174 178 - ret = clk_prepare_enable(gchip->clk); 179 - if (ret) 180 - return ret; 181 - } 175 + ret = clk_prepare_enable(gchip->clk); 176 + if (ret) 177 + return ret; 182 178 183 179 spin_lock_init(&gchip->lock); 184 180 ··· 186 186 gchip->gc.free = mb86s70_gpio_free; 187 187 gchip->gc.get = mb86s70_gpio_get; 188 188 gchip->gc.set = mb86s70_gpio_set; 189 + gchip->gc.to_irq = mb86s70_gpio_to_irq; 189 190 gchip->gc.label = dev_name(&pdev->dev); 190 191 gchip->gc.ngpio = 32; 191 192 gchip->gc.owner = THIS_MODULE; 192 193 gchip->gc.parent = &pdev->dev; 193 194 gchip->gc.base = -1; 194 - 195 - if (has_acpi_companion(&pdev->dev)) 196 - gchip->gc.to_irq = mb86s70_gpio_to_irq; 197 195 198 196 ret = gpiochip_add_data(&gchip->gc, gchip); 199 197 if (ret) { ··· 200 202 return ret; 201 203 } 202 204 203 - if (has_acpi_companion(&pdev->dev)) 204 - acpi_gpiochip_request_interrupts(&gchip->gc); 205 + acpi_gpiochip_request_interrupts(&gchip->gc); 205 206 206 207 return 0; 207 208 } ··· 209 212 { 210 213 struct mb86s70_gpio_chip *gchip = platform_get_drvdata(pdev); 211 214 212 - if (has_acpi_companion(&pdev->dev)) 213 - acpi_gpiochip_free_interrupts(&gchip->gc); 215 + acpi_gpiochip_free_interrupts(&gchip->gc); 214 216 gpiochip_remove(&gchip->gc); 215 217 clk_disable_unprepare(gchip->clk); 216 218
+7 -3
drivers/gpio/gpio-merrifield.c
··· 443 443 444 444 base = pcim_iomap_table(pdev)[1]; 445 445 446 - irq_base = readl(base); 447 - gpio_base = readl(sizeof(u32) + base); 446 + irq_base = readl(base + 0 * sizeof(u32)); 447 + gpio_base = readl(base + 1 * sizeof(u32)); 448 448 449 449 /* Release the IO mapping, since we already get the info from BAR1 */ 450 450 pcim_iounmap_regions(pdev, BIT(1)); ··· 473 473 474 474 raw_spin_lock_init(&priv->lock); 475 475 476 + retval = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); 477 + if (retval < 0) 478 + return retval; 479 + 476 480 girq = &priv->chip.irq; 477 481 girq->chip = &mrfld_irqchip; 478 482 girq->init_hw = mrfld_irq_init_hw; ··· 486 482 sizeof(*girq->parents), GFP_KERNEL); 487 483 if (!girq->parents) 488 484 return -ENOMEM; 489 - girq->parents[0] = pdev->irq; 485 + girq->parents[0] = pci_irq_vector(pdev, 0); 490 486 girq->first = irq_base; 491 487 girq->default_type = IRQ_TYPE_NONE; 492 488 girq->handler = handle_bad_irq;
+2 -3
drivers/gpio/gpio-mlxbf2.c
··· 14 14 #include <linux/resource.h> 15 15 #include <linux/spinlock.h> 16 16 #include <linux/types.h> 17 - #include <linux/version.h> 18 17 19 18 /* 20 19 * There are 3 YU GPIO blocks: ··· 109 110 } 110 111 111 112 yu_arm_gpio_lock_param.io = devm_ioremap(dev, res->start, size); 112 - if (IS_ERR(yu_arm_gpio_lock_param.io)) 113 - ret = PTR_ERR(yu_arm_gpio_lock_param.io); 113 + if (!yu_arm_gpio_lock_param.io) 114 + ret = -ENOMEM; 114 115 115 116 exit: 116 117 mutex_unlock(yu_arm_gpio_lock_param.lock);
+1 -1
drivers/gpio/gpio-mm-lantiq.c
··· 36 36 * @chip: Pointer to our private data structure. 37 37 * 38 38 * Write the shadow value to the EBU to set the gpios. We need to set the 39 - * global EBU lock to make sure that PCI/MTD dont break. 39 + * global EBU lock to make sure that PCI/MTD don't break. 40 40 */ 41 41 static void ltq_mm_apply(struct ltq_mm *chip) 42 42 {
+59 -37
drivers/gpio/gpio-pca953x.c
··· 306 306 .writeable_reg = pca953x_writeable_register, 307 307 .volatile_reg = pca953x_volatile_register, 308 308 309 + .disable_locking = true, 309 310 .cache_type = REGCACHE_RBTREE, 310 - /* REVISIT: should be 0x7f but some 24 bit chips use REG_ADDR_AI */ 311 - .max_register = 0xff, 311 + .max_register = 0x7f, 312 312 }; 313 313 314 - static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off, 315 - bool write, bool addrinc) 314 + static const struct regmap_config pca953x_ai_i2c_regmap = { 315 + .reg_bits = 8, 316 + .val_bits = 8, 317 + 318 + .read_flag_mask = REG_ADDR_AI, 319 + .write_flag_mask = REG_ADDR_AI, 320 + 321 + .readable_reg = pca953x_readable_register, 322 + .writeable_reg = pca953x_writeable_register, 323 + .volatile_reg = pca953x_volatile_register, 324 + 325 + .cache_type = REGCACHE_RBTREE, 326 + .max_register = 0x7f, 327 + }; 328 + 329 + static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off) 316 330 { 317 331 int bank_shift = pca953x_bank_shift(chip); 318 332 int addr = (reg & PCAL_GPIO_MASK) << bank_shift; 319 333 int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; 320 334 u8 regaddr = pinctrl | addr | (off / BANK_SZ); 321 335 322 - /* Single byte read doesn't need AI bit set. */ 323 - if (!addrinc) 324 - return regaddr; 325 - 326 - /* Chips with 24 and more GPIOs always support Auto Increment */ 327 - if (write && NBANK(chip) > 2) 328 - regaddr |= REG_ADDR_AI; 329 - 330 - /* PCA9575 needs address-increment on multi-byte writes */ 331 - if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) 332 - regaddr |= REG_ADDR_AI; 333 - 334 336 return regaddr; 335 337 } 336 338 337 339 static int pca953x_write_regs(struct pca953x_chip *chip, int reg, unsigned long *val) 338 340 { 339 - u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true); 341 + u8 regaddr = pca953x_recalc_addr(chip, reg, 0); 340 342 u8 value[MAX_BANK]; 341 343 int i, ret; 342 344 ··· 356 354 357 355 static int pca953x_read_regs(struct pca953x_chip *chip, int reg, unsigned long *val) 358 356 { 359 - u8 regaddr = pca953x_recalc_addr(chip, reg, 0, false, true); 357 + u8 regaddr = pca953x_recalc_addr(chip, reg, 0); 360 358 u8 value[MAX_BANK]; 361 359 int i, ret; 362 360 ··· 375 373 static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 376 374 { 377 375 struct pca953x_chip *chip = gpiochip_get_data(gc); 378 - u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, 379 - true, false); 376 + u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off); 380 377 u8 bit = BIT(off % BANK_SZ); 381 378 int ret; 382 379 ··· 389 388 unsigned off, int val) 390 389 { 391 390 struct pca953x_chip *chip = gpiochip_get_data(gc); 392 - u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, 393 - true, false); 394 - u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off, 395 - true, false); 391 + u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off); 392 + u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off); 396 393 u8 bit = BIT(off % BANK_SZ); 397 394 int ret; 398 395 ··· 410 411 static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) 411 412 { 412 413 struct pca953x_chip *chip = gpiochip_get_data(gc); 413 - u8 inreg = pca953x_recalc_addr(chip, chip->regs->input, off, 414 - true, false); 414 + u8 inreg = pca953x_recalc_addr(chip, chip->regs->input, off); 415 415 u8 bit = BIT(off % BANK_SZ); 416 416 u32 reg_val; 417 417 int ret; ··· 434 436 static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 435 437 { 436 438 struct pca953x_chip *chip = gpiochip_get_data(gc); 437 - u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off, 438 - true, false); 439 + u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off); 439 440 u8 bit = BIT(off % BANK_SZ); 440 441 441 442 mutex_lock(&chip->i2c_lock); ··· 445 448 static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off) 446 449 { 447 450 struct pca953x_chip *chip = gpiochip_get_data(gc); 448 - u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, 449 - true, false); 451 + u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off); 450 452 u8 bit = BIT(off % BANK_SZ); 451 453 u32 reg_val; 452 454 int ret; ··· 460 464 return GPIO_LINE_DIRECTION_IN; 461 465 462 466 return GPIO_LINE_DIRECTION_OUT; 467 + } 468 + 469 + static int pca953x_gpio_get_multiple(struct gpio_chip *gc, 470 + unsigned long *mask, unsigned long *bits) 471 + { 472 + struct pca953x_chip *chip = gpiochip_get_data(gc); 473 + DECLARE_BITMAP(reg_val, MAX_LINE); 474 + int ret; 475 + 476 + mutex_lock(&chip->i2c_lock); 477 + ret = pca953x_read_regs(chip, chip->regs->input, reg_val); 478 + mutex_unlock(&chip->i2c_lock); 479 + if (ret) 480 + return ret; 481 + 482 + bitmap_replace(bits, bits, reg_val, mask, gc->ngpio); 483 + return 0; 463 484 } 464 485 465 486 static void pca953x_gpio_set_multiple(struct gpio_chip *gc, ··· 502 489 unsigned int offset, 503 490 unsigned long config) 504 491 { 505 - u8 pull_en_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_EN, offset, 506 - true, false); 507 - u8 pull_sel_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_SEL, offset, 508 - true, false); 492 + u8 pull_en_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_EN, offset); 493 + u8 pull_sel_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_SEL, offset); 509 494 u8 bit = BIT(offset % BANK_SZ); 510 495 int ret; 511 496 ··· 562 551 gc->get = pca953x_gpio_get_value; 563 552 gc->set = pca953x_gpio_set_value; 564 553 gc->get_direction = pca953x_gpio_get_direction; 554 + gc->get_multiple = pca953x_gpio_get_multiple; 565 555 gc->set_multiple = pca953x_gpio_set_multiple; 566 556 gc->set_config = pca953x_gpio_set_config; 567 557 gc->can_sleep = true; ··· 875 863 int ret; 876 864 u32 invert = 0; 877 865 struct regulator *reg; 866 + const struct regmap_config *regmap_config; 878 867 879 868 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 880 869 if (chip == NULL) ··· 938 925 939 926 i2c_set_clientdata(client, chip); 940 927 941 - chip->regmap = devm_regmap_init_i2c(client, &pca953x_i2c_regmap); 928 + pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); 929 + 930 + if (NBANK(chip) > 2 || PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) { 931 + dev_info(&client->dev, "using AI\n"); 932 + regmap_config = &pca953x_ai_i2c_regmap; 933 + } else { 934 + dev_info(&client->dev, "using no AI\n"); 935 + regmap_config = &pca953x_i2c_regmap; 936 + } 937 + 938 + chip->regmap = devm_regmap_init_i2c(client, regmap_config); 942 939 if (IS_ERR(chip->regmap)) { 943 940 ret = PTR_ERR(chip->regmap); 944 941 goto err_exit; ··· 979 956 /* initialize cached registers from their original values. 980 957 * we can't share this chip with another i2c master. 981 958 */ 982 - pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); 983 959 984 960 if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { 985 961 chip->regs = &pca953x_regs; ··· 1176 1154 .name = "pca953x", 1177 1155 .pm = &pca953x_pm_ops, 1178 1156 .of_match_table = pca953x_dt_ids, 1179 - .acpi_match_table = ACPI_PTR(pca953x_acpi_ids), 1157 + .acpi_match_table = pca953x_acpi_ids, 1180 1158 }, 1181 1159 .probe = pca953x_probe, 1182 1160 .remove = pca953x_remove,
+37 -36
drivers/gpio/gpio-pch.c
··· 2 2 /* 3 3 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. 4 4 */ 5 + #include <linux/bits.h> 5 6 #include <linux/gpio/driver.h> 6 7 #include <linux/interrupt.h> 7 8 #include <linux/irq.h> ··· 12 11 #include <linux/slab.h> 13 12 14 13 #define PCH_EDGE_FALLING 0 15 - #define PCH_EDGE_RISING BIT(0) 16 - #define PCH_LEVEL_L BIT(1) 17 - #define PCH_LEVEL_H (BIT(0) | BIT(1)) 18 - #define PCH_EDGE_BOTH BIT(2) 19 - #define PCH_IM_MASK (BIT(0) | BIT(1) | BIT(2)) 14 + #define PCH_EDGE_RISING 1 15 + #define PCH_LEVEL_L 2 16 + #define PCH_LEVEL_H 3 17 + #define PCH_EDGE_BOTH 4 18 + #define PCH_IM_MASK GENMASK(2, 0) 20 19 21 20 #define PCH_IRQ_BASE 24 22 21 ··· 104 103 spin_lock_irqsave(&chip->spinlock, flags); 105 104 reg_val = ioread32(&chip->reg->po); 106 105 if (val) 107 - reg_val |= (1 << nr); 106 + reg_val |= BIT(nr); 108 107 else 109 - reg_val &= ~(1 << nr); 108 + reg_val &= ~BIT(nr); 110 109 111 110 iowrite32(reg_val, &chip->reg->po); 112 111 spin_unlock_irqrestore(&chip->spinlock, flags); ··· 116 115 { 117 116 struct pch_gpio *chip = gpiochip_get_data(gpio); 118 117 119 - return (ioread32(&chip->reg->pi) >> nr) & 1; 118 + return !!(ioread32(&chip->reg->pi) & BIT(nr)); 120 119 } 121 120 122 121 static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, ··· 131 130 132 131 reg_val = ioread32(&chip->reg->po); 133 132 if (val) 134 - reg_val |= (1 << nr); 133 + reg_val |= BIT(nr); 135 134 else 136 - reg_val &= ~(1 << nr); 135 + reg_val &= ~BIT(nr); 137 136 iowrite32(reg_val, &chip->reg->po); 138 137 139 - pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); 140 - pm |= (1 << nr); 138 + pm = ioread32(&chip->reg->pm); 139 + pm &= BIT(gpio_pins[chip->ioh]) - 1; 140 + pm |= BIT(nr); 141 141 iowrite32(pm, &chip->reg->pm); 142 142 143 143 spin_unlock_irqrestore(&chip->spinlock, flags); ··· 153 151 unsigned long flags; 154 152 155 153 spin_lock_irqsave(&chip->spinlock, flags); 156 - pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); 157 - pm &= ~(1 << nr); 154 + pm = ioread32(&chip->reg->pm); 155 + pm &= BIT(gpio_pins[chip->ioh]) - 1; 156 + pm &= ~BIT(nr); 158 157 iowrite32(pm, &chip->reg->pm); 159 158 spin_unlock_irqrestore(&chip->spinlock, flags); 160 159 ··· 229 226 int ch, irq = d->irq; 230 227 231 228 ch = irq - chip->irq_base; 232 - if (irq <= chip->irq_base + 7) { 229 + if (irq < chip->irq_base + 8) { 233 230 im_reg = &chip->reg->im0; 234 - im_pos = ch; 231 + im_pos = ch - 0; 235 232 } else { 236 233 im_reg = &chip->reg->im1; 237 234 im_pos = ch - 8; 238 235 } 239 236 dev_dbg(chip->dev, "irq=%d type=%d ch=%d pos=%d\n", irq, type, ch, im_pos); 240 - 241 - spin_lock_irqsave(&chip->spinlock, flags); 242 237 243 238 switch (type) { 244 239 case IRQ_TYPE_EDGE_RISING: ··· 255 254 val = PCH_LEVEL_L; 256 255 break; 257 256 default: 258 - goto unlock; 257 + return 0; 259 258 } 259 + 260 + spin_lock_irqsave(&chip->spinlock, flags); 260 261 261 262 /* Set interrupt mode */ 262 263 im = ioread32(im_reg) & ~(PCH_IM_MASK << (im_pos * 4)); 263 264 iowrite32(im | (val << (im_pos * 4)), im_reg); 264 265 265 266 /* And the handler */ 266 - if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 267 + if (type & IRQ_TYPE_LEVEL_MASK) 267 268 irq_set_handler_locked(d, handle_level_irq); 268 - else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 269 + else if (type & IRQ_TYPE_EDGE_BOTH) 269 270 irq_set_handler_locked(d, handle_edge_irq); 270 271 271 - unlock: 272 272 spin_unlock_irqrestore(&chip->spinlock, flags); 273 273 return 0; 274 274 } ··· 279 277 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 280 278 struct pch_gpio *chip = gc->private; 281 279 282 - iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imaskclr); 280 + iowrite32(BIT(d->irq - chip->irq_base), &chip->reg->imaskclr); 283 281 } 284 282 285 283 static void pch_irq_mask(struct irq_data *d) ··· 287 285 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 288 286 struct pch_gpio *chip = gc->private; 289 287 290 - iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imask); 288 + iowrite32(BIT(d->irq - chip->irq_base), &chip->reg->imask); 291 289 } 292 290 293 291 static void pch_irq_ack(struct irq_data *d) ··· 295 293 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 296 294 struct pch_gpio *chip = gc->private; 297 295 298 - iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->iclr); 296 + iowrite32(BIT(d->irq - chip->irq_base), &chip->reg->iclr); 299 297 } 300 298 301 299 static irqreturn_t pch_gpio_handler(int irq, void *dev_id) 302 300 { 303 301 struct pch_gpio *chip = dev_id; 304 302 unsigned long reg_val = ioread32(&chip->reg->istatus); 305 - int i, ret = IRQ_NONE; 303 + int i; 306 304 307 - for_each_set_bit(i, &reg_val, gpio_pins[chip->ioh]) { 308 - dev_dbg(chip->dev, "[%d]:irq=%d status=0x%lx\n", i, irq, reg_val); 305 + dev_dbg(chip->dev, "irq=%d status=0x%lx\n", irq, reg_val); 306 + 307 + reg_val &= BIT(gpio_pins[chip->ioh]) - 1; 308 + for_each_set_bit(i, &reg_val, gpio_pins[chip->ioh]) 309 309 generic_handle_irq(chip->irq_base + i); 310 - ret = IRQ_HANDLED; 311 - } 312 - return ret; 310 + 311 + return IRQ_RETVAL(reg_val); 313 312 } 314 313 315 314 static int pch_gpio_alloc_generic_chip(struct pch_gpio *chip, ··· 347 344 s32 ret; 348 345 struct pch_gpio *chip; 349 346 int irq_base; 350 - u32 msk; 351 347 352 348 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 353 349 if (chip == NULL) ··· 359 357 return ret; 360 358 } 361 359 362 - ret = pcim_iomap_regions(pdev, 1 << 1, KBUILD_MODNAME); 360 + ret = pcim_iomap_regions(pdev, BIT(1), KBUILD_MODNAME); 363 361 if (ret) { 364 362 dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret); 365 363 return ret; ··· 395 393 chip->irq_base = irq_base; 396 394 397 395 /* Mask all interrupts, but enable them */ 398 - msk = (1 << gpio_pins[chip->ioh]) - 1; 399 - iowrite32(msk, &chip->reg->imask); 400 - iowrite32(msk, &chip->reg->ien); 396 + iowrite32(BIT(gpio_pins[chip->ioh]) - 1, &chip->reg->imask); 397 + iowrite32(BIT(gpio_pins[chip->ioh]) - 1, &chip->reg->ien); 401 398 402 399 ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler, 403 400 IRQF_SHARED, KBUILD_MODNAME, chip);
+4 -5
drivers/gpio/gpio-pl061.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/irq.h> 18 18 #include <linux/irqchip/chained_irq.h> 19 + #include <linux/module.h> 19 20 #include <linux/bitops.h> 20 21 #include <linux/gpio/driver.h> 21 22 #include <linux/device.h> ··· 409 408 }, 410 409 { 0, 0 }, 411 410 }; 411 + MODULE_DEVICE_TABLE(amba, pl061_ids); 412 412 413 413 static struct amba_driver pl061_gpio_driver = { 414 414 .drv = { ··· 421 419 .id_table = pl061_ids, 422 420 .probe = pl061_probe, 423 421 }; 422 + module_amba_driver(pl061_gpio_driver); 424 423 425 - static int __init pl061_gpio_init(void) 426 - { 427 - return amba_driver_register(&pl061_gpio_driver); 428 - } 429 - device_initcall(pl061_gpio_init); 424 + MODULE_LICENSE("GPL v2");
+3 -1
drivers/gpio/gpio-rcar.c
··· 250 250 int error; 251 251 252 252 error = pm_runtime_get_sync(p->dev); 253 - if (error < 0) 253 + if (error < 0) { 254 + pm_runtime_put(p->dev); 254 255 return error; 256 + } 255 257 256 258 error = pinctrl_gpio_request(chip->base + offset); 257 259 if (error)
+349
drivers/gpio/gpio-regmap.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * regmap based generic GPIO driver 4 + * 5 + * Copyright 2020 Michael Walle <michael@walle.cc> 6 + */ 7 + 8 + #include <linux/gpio/driver.h> 9 + #include <linux/gpio/regmap.h> 10 + #include <linux/kernel.h> 11 + #include <linux/module.h> 12 + #include <linux/regmap.h> 13 + 14 + struct gpio_regmap { 15 + struct device *parent; 16 + struct regmap *regmap; 17 + struct gpio_chip gpio_chip; 18 + 19 + int reg_stride; 20 + int ngpio_per_reg; 21 + unsigned int reg_dat_base; 22 + unsigned int reg_set_base; 23 + unsigned int reg_clr_base; 24 + unsigned int reg_dir_in_base; 25 + unsigned int reg_dir_out_base; 26 + 27 + int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, 28 + unsigned int offset, unsigned int *reg, 29 + unsigned int *mask); 30 + 31 + void *driver_data; 32 + }; 33 + 34 + static unsigned int gpio_regmap_addr(unsigned int addr) 35 + { 36 + if (addr == GPIO_REGMAP_ADDR_ZERO) 37 + return 0; 38 + 39 + return addr; 40 + } 41 + 42 + static int gpio_regmap_simple_xlate(struct gpio_regmap *gpio, 43 + unsigned int base, unsigned int offset, 44 + unsigned int *reg, unsigned int *mask) 45 + { 46 + unsigned int line = offset % gpio->ngpio_per_reg; 47 + unsigned int stride = offset / gpio->ngpio_per_reg; 48 + 49 + *reg = base + stride * gpio->reg_stride; 50 + *mask = BIT(line); 51 + 52 + return 0; 53 + } 54 + 55 + static int gpio_regmap_get(struct gpio_chip *chip, unsigned int offset) 56 + { 57 + struct gpio_regmap *gpio = gpiochip_get_data(chip); 58 + unsigned int base, val, reg, mask; 59 + int ret; 60 + 61 + /* we might not have an output register if we are input only */ 62 + if (gpio->reg_dat_base) 63 + base = gpio_regmap_addr(gpio->reg_dat_base); 64 + else 65 + base = gpio_regmap_addr(gpio->reg_set_base); 66 + 67 + ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask); 68 + if (ret) 69 + return ret; 70 + 71 + ret = regmap_read(gpio->regmap, reg, &val); 72 + if (ret) 73 + return ret; 74 + 75 + return !!(val & mask); 76 + } 77 + 78 + static void gpio_regmap_set(struct gpio_chip *chip, unsigned int offset, 79 + int val) 80 + { 81 + struct gpio_regmap *gpio = gpiochip_get_data(chip); 82 + unsigned int base = gpio_regmap_addr(gpio->reg_set_base); 83 + unsigned int reg, mask; 84 + 85 + gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask); 86 + if (val) 87 + regmap_update_bits(gpio->regmap, reg, mask, mask); 88 + else 89 + regmap_update_bits(gpio->regmap, reg, mask, 0); 90 + } 91 + 92 + static void gpio_regmap_set_with_clear(struct gpio_chip *chip, 93 + unsigned int offset, int val) 94 + { 95 + struct gpio_regmap *gpio = gpiochip_get_data(chip); 96 + unsigned int base, reg, mask; 97 + 98 + if (val) 99 + base = gpio_regmap_addr(gpio->reg_set_base); 100 + else 101 + base = gpio_regmap_addr(gpio->reg_clr_base); 102 + 103 + gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask); 104 + regmap_write(gpio->regmap, reg, mask); 105 + } 106 + 107 + static int gpio_regmap_get_direction(struct gpio_chip *chip, 108 + unsigned int offset) 109 + { 110 + struct gpio_regmap *gpio = gpiochip_get_data(chip); 111 + unsigned int base, val, reg, mask; 112 + int invert, ret; 113 + 114 + if (gpio->reg_dir_out_base) { 115 + base = gpio_regmap_addr(gpio->reg_dir_out_base); 116 + invert = 0; 117 + } else if (gpio->reg_dir_in_base) { 118 + base = gpio_regmap_addr(gpio->reg_dir_in_base); 119 + invert = 1; 120 + } else { 121 + return -EOPNOTSUPP; 122 + } 123 + 124 + ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask); 125 + if (ret) 126 + return ret; 127 + 128 + ret = regmap_read(gpio->regmap, reg, &val); 129 + if (ret) 130 + return ret; 131 + 132 + if (!!(val & mask) ^ invert) 133 + return GPIO_LINE_DIRECTION_OUT; 134 + else 135 + return GPIO_LINE_DIRECTION_IN; 136 + } 137 + 138 + static int gpio_regmap_set_direction(struct gpio_chip *chip, 139 + unsigned int offset, bool output) 140 + { 141 + struct gpio_regmap *gpio = gpiochip_get_data(chip); 142 + unsigned int base, val, reg, mask; 143 + int invert, ret; 144 + 145 + if (gpio->reg_dir_out_base) { 146 + base = gpio_regmap_addr(gpio->reg_dir_out_base); 147 + invert = 0; 148 + } else if (gpio->reg_dir_in_base) { 149 + base = gpio_regmap_addr(gpio->reg_dir_in_base); 150 + invert = 1; 151 + } else { 152 + return -EOPNOTSUPP; 153 + } 154 + 155 + ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask); 156 + if (ret) 157 + return ret; 158 + 159 + if (invert) 160 + val = output ? 0 : mask; 161 + else 162 + val = output ? mask : 0; 163 + 164 + return regmap_update_bits(gpio->regmap, reg, mask, val); 165 + } 166 + 167 + static int gpio_regmap_direction_input(struct gpio_chip *chip, 168 + unsigned int offset) 169 + { 170 + return gpio_regmap_set_direction(chip, offset, false); 171 + } 172 + 173 + static int gpio_regmap_direction_output(struct gpio_chip *chip, 174 + unsigned int offset, int value) 175 + { 176 + gpio_regmap_set(chip, offset, value); 177 + 178 + return gpio_regmap_set_direction(chip, offset, true); 179 + } 180 + 181 + void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data) 182 + { 183 + gpio->driver_data = data; 184 + } 185 + EXPORT_SYMBOL_GPL(gpio_regmap_set_drvdata); 186 + 187 + void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio) 188 + { 189 + return gpio->driver_data; 190 + } 191 + EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); 192 + 193 + /** 194 + * gpio_regmap_register() - Register a generic regmap GPIO controller 195 + * @config: configuration for gpio_regmap 196 + * 197 + * Return: A pointer to the registered gpio_regmap or ERR_PTR error value. 198 + */ 199 + struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config) 200 + { 201 + struct gpio_regmap *gpio; 202 + struct gpio_chip *chip; 203 + int ret; 204 + 205 + if (!config->parent) 206 + return ERR_PTR(-EINVAL); 207 + 208 + if (!config->ngpio) 209 + return ERR_PTR(-EINVAL); 210 + 211 + /* we need at least one */ 212 + if (!config->reg_dat_base && !config->reg_set_base) 213 + return ERR_PTR(-EINVAL); 214 + 215 + /* if we have a direction register we need both input and output */ 216 + if ((config->reg_dir_out_base || config->reg_dir_in_base) && 217 + (!config->reg_dat_base || !config->reg_set_base)) 218 + return ERR_PTR(-EINVAL); 219 + 220 + /* we don't support having both registers simultaneously for now */ 221 + if (config->reg_dir_out_base && config->reg_dir_in_base) 222 + return ERR_PTR(-EINVAL); 223 + 224 + gpio = kzalloc(sizeof(*gpio), GFP_KERNEL); 225 + if (!gpio) 226 + return ERR_PTR(-ENOMEM); 227 + 228 + gpio->parent = config->parent; 229 + gpio->regmap = config->regmap; 230 + gpio->ngpio_per_reg = config->ngpio_per_reg; 231 + gpio->reg_stride = config->reg_stride; 232 + gpio->reg_mask_xlate = config->reg_mask_xlate; 233 + gpio->reg_dat_base = config->reg_dat_base; 234 + gpio->reg_set_base = config->reg_set_base; 235 + gpio->reg_clr_base = config->reg_clr_base; 236 + gpio->reg_dir_in_base = config->reg_dir_in_base; 237 + gpio->reg_dir_out_base = config->reg_dir_out_base; 238 + 239 + /* if not set, assume there is only one register */ 240 + if (!gpio->ngpio_per_reg) 241 + gpio->ngpio_per_reg = config->ngpio; 242 + 243 + /* if not set, assume they are consecutive */ 244 + if (!gpio->reg_stride) 245 + gpio->reg_stride = 1; 246 + 247 + if (!gpio->reg_mask_xlate) 248 + gpio->reg_mask_xlate = gpio_regmap_simple_xlate; 249 + 250 + chip = &gpio->gpio_chip; 251 + chip->parent = config->parent; 252 + chip->base = -1; 253 + chip->ngpio = config->ngpio; 254 + chip->names = config->names; 255 + chip->label = config->label ?: dev_name(config->parent); 256 + 257 + /* 258 + * If our regmap is fast_io we should probably set can_sleep to false. 259 + * Right now, the regmap doesn't save this property, nor is there any 260 + * access function for it. 261 + * The only regmap type which uses fast_io is regmap-mmio. For now, 262 + * assume a safe default of true here. 263 + */ 264 + chip->can_sleep = true; 265 + 266 + chip->get = gpio_regmap_get; 267 + if (gpio->reg_set_base && gpio->reg_clr_base) 268 + chip->set = gpio_regmap_set_with_clear; 269 + else if (gpio->reg_set_base) 270 + chip->set = gpio_regmap_set; 271 + 272 + if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) { 273 + chip->get_direction = gpio_regmap_get_direction; 274 + chip->direction_input = gpio_regmap_direction_input; 275 + chip->direction_output = gpio_regmap_direction_output; 276 + } 277 + 278 + ret = gpiochip_add_data(chip, gpio); 279 + if (ret < 0) 280 + goto err_free_gpio; 281 + 282 + if (config->irq_domain) { 283 + ret = gpiochip_irqchip_add_domain(chip, config->irq_domain); 284 + if (ret) 285 + goto err_remove_gpiochip; 286 + } 287 + 288 + return gpio; 289 + 290 + err_remove_gpiochip: 291 + gpiochip_remove(chip); 292 + err_free_gpio: 293 + kfree(gpio); 294 + return ERR_PTR(ret); 295 + } 296 + EXPORT_SYMBOL_GPL(gpio_regmap_register); 297 + 298 + /** 299 + * gpio_regmap_unregister() - Unregister a generic regmap GPIO controller 300 + * @gpio: gpio_regmap device to unregister 301 + */ 302 + void gpio_regmap_unregister(struct gpio_regmap *gpio) 303 + { 304 + gpiochip_remove(&gpio->gpio_chip); 305 + kfree(gpio); 306 + } 307 + EXPORT_SYMBOL_GPL(gpio_regmap_unregister); 308 + 309 + static void devm_gpio_regmap_unregister(struct device *dev, void *res) 310 + { 311 + gpio_regmap_unregister(*(struct gpio_regmap **)res); 312 + } 313 + 314 + /** 315 + * devm_gpio_regmap_register() - resource managed gpio_regmap_register() 316 + * @dev: device that is registering this GPIO device 317 + * @config: configuration for gpio_regmap 318 + * 319 + * Managed gpio_regmap_register(). For generic regmap GPIO device registered by 320 + * this function, gpio_regmap_unregister() is automatically called on driver 321 + * detach. See gpio_regmap_register() for more information. 322 + * 323 + * Return: A pointer to the registered gpio_regmap or ERR_PTR error value. 324 + */ 325 + struct gpio_regmap *devm_gpio_regmap_register(struct device *dev, 326 + const struct gpio_regmap_config *config) 327 + { 328 + struct gpio_regmap **ptr, *gpio; 329 + 330 + ptr = devres_alloc(devm_gpio_regmap_unregister, sizeof(*ptr), 331 + GFP_KERNEL); 332 + if (!ptr) 333 + return ERR_PTR(-ENOMEM); 334 + 335 + gpio = gpio_regmap_register(config); 336 + if (!IS_ERR(gpio)) { 337 + *ptr = gpio; 338 + devres_add(dev, ptr); 339 + } else { 340 + devres_free(ptr); 341 + } 342 + 343 + return gpio; 344 + } 345 + EXPORT_SYMBOL_GPL(devm_gpio_regmap_register); 346 + 347 + MODULE_AUTHOR("Michael Walle <michael@walle.cc>"); 348 + MODULE_DESCRIPTION("GPIO generic regmap driver core"); 349 + MODULE_LICENSE("GPL");
+1
drivers/gpio/gpio-tegra186.c
··· 894 894 /* sentinel */ 895 895 } 896 896 }; 897 + MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match); 897 898 898 899 static struct platform_driver tegra186_gpio_driver = { 899 900 .driver = {
+5 -9
drivers/gpio/gpio-xgene-sb.c
··· 10 10 11 11 #include <linux/module.h> 12 12 #include <linux/io.h> 13 + #include <linux/of.h> 13 14 #include <linux/platform_device.h> 14 - #include <linux/of_gpio.h> 15 15 #include <linux/gpio/driver.h> 16 16 #include <linux/acpi.h> 17 17 ··· 122 122 fwspec.fwnode = gc->parent->fwnode; 123 123 fwspec.param_count = 2; 124 124 fwspec.param[0] = GPIO_TO_HWIRQ(priv, gpio); 125 - fwspec.param[1] = IRQ_TYPE_NONE; 125 + fwspec.param[1] = IRQ_TYPE_EDGE_RISING; 126 126 return irq_create_fwspec_mapping(&fwspec); 127 127 } 128 128 ··· 290 290 291 291 dev_info(&pdev->dev, "X-Gene GPIO Standby driver registered\n"); 292 292 293 - if (priv->nirq > 0) { 294 - /* Register interrupt handlers for gpio signaled acpi events */ 295 - acpi_gpiochip_request_interrupts(&priv->gc); 296 - } 293 + /* Register interrupt handlers for GPIO signaled ACPI Events */ 294 + acpi_gpiochip_request_interrupts(&priv->gc); 297 295 298 296 return ret; 299 297 } ··· 300 302 { 301 303 struct xgene_gpio_sb *priv = platform_get_drvdata(pdev); 302 304 303 - if (priv->nirq > 0) { 304 - acpi_gpiochip_free_interrupts(&priv->gc); 305 - } 305 + acpi_gpiochip_free_interrupts(&priv->gc); 306 306 307 307 irq_domain_remove(priv->irq_domain); 308 308
+3 -3
drivers/gpio/gpiolib-acpi.c
··· 1353 1353 } 1354 1354 1355 1355 /* Run deferred acpi_gpiochip_request_irqs() */ 1356 - static int acpi_gpio_handle_deferred_request_irqs(void) 1356 + static int __init acpi_gpio_handle_deferred_request_irqs(void) 1357 1357 { 1358 1358 struct acpi_gpio_chip *acpi_gpio, *tmp; 1359 1359 ··· 1371 1371 /* We must use _sync so that this runs after the first deferred_probe run */ 1372 1372 late_initcall_sync(acpi_gpio_handle_deferred_request_irqs); 1373 1373 1374 - static const struct dmi_system_id gpiolib_acpi_quirks[] = { 1374 + static const struct dmi_system_id gpiolib_acpi_quirks[] __initconst = { 1375 1375 { 1376 1376 /* 1377 1377 * The Minix Neo Z83-4 has a micro-USB-B id-pin handler for ··· 1455 1455 {} /* Terminating entry */ 1456 1456 }; 1457 1457 1458 - static int acpi_gpio_setup_params(void) 1458 + static int __init acpi_gpio_setup_params(void) 1459 1459 { 1460 1460 const struct acpi_gpiolib_dmi_quirk *quirk = NULL; 1461 1461 const struct dmi_system_id *id;
+4 -1
drivers/gpio/gpiolib-devprop.c
··· 37 37 if (count < 0) 38 38 return; 39 39 40 - if (count > gdev->ngpio) 40 + if (count > gdev->ngpio) { 41 + dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", 42 + count, gdev->ngpio); 41 43 count = gdev->ngpio; 44 + } 42 45 43 46 names = kcalloc(count, sizeof(*names), GFP_KERNEL); 44 47 if (!names)
+10
drivers/gpio/gpiolib-of.c
··· 344 344 if (transitory) 345 345 lflags |= GPIO_TRANSITORY; 346 346 347 + if (flags & OF_GPIO_PULL_UP) 348 + lflags |= GPIO_PULL_UP; 349 + 350 + if (flags & OF_GPIO_PULL_DOWN) 351 + lflags |= GPIO_PULL_DOWN; 352 + 347 353 ret = gpiod_configure_flags(desc, propname, lflags, dflags); 348 354 if (ret < 0) { 349 355 gpiod_put(desc); ··· 591 585 *lflags |= GPIO_ACTIVE_LOW; 592 586 if (xlate_flags & OF_GPIO_TRANSITORY) 593 587 *lflags |= GPIO_TRANSITORY; 588 + if (xlate_flags & OF_GPIO_PULL_UP) 589 + *lflags |= GPIO_PULL_UP; 590 + if (xlate_flags & OF_GPIO_PULL_DOWN) 591 + *lflags |= GPIO_PULL_DOWN; 594 592 595 593 if (of_property_read_bool(np, "input")) 596 594 *dflags |= GPIOD_IN;
+116 -51
drivers/gpio/gpiolib.c
··· 296 296 297 297 /* 298 298 * Convert a GPIO name to its descriptor 299 + * Note that there is no guarantee that GPIO names are globally unique! 300 + * Hence this function will return, if it exists, a reference to the first GPIO 301 + * line found that matches the given name. 299 302 */ 300 303 static struct gpio_desc *gpio_name_to_desc(const char * const name) 301 304 { ··· 332 329 } 333 330 334 331 /* 335 - * Takes the names from gc->names and checks if they are all unique. If they 336 - * are, they are assigned to their gpio descriptors. 332 + * Take the names from gc->names and assign them to their GPIO descriptors. 333 + * Warn if a name is already used for a GPIO line on a different GPIO chip. 337 334 * 338 - * Warning if one of the names is already used for a different GPIO. 335 + * Note that: 336 + * 1. Non-unique names are still accepted, 337 + * 2. Name collisions within the same GPIO chip are not reported. 339 338 */ 340 339 static int gpiochip_set_desc_names(struct gpio_chip *gc) 341 340 { ··· 1272 1267 if (copy_to_user(ip, &chipinfo, sizeof(chipinfo))) 1273 1268 return -EFAULT; 1274 1269 return 0; 1275 - } else if (cmd == GPIO_GET_LINEINFO_IOCTL || 1276 - cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) { 1270 + } else if (cmd == GPIO_GET_LINEINFO_IOCTL) { 1277 1271 struct gpioline_info lineinfo; 1278 1272 1279 1273 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) ··· 1284 1280 1285 1281 hwgpio = gpio_chip_hwgpio(desc); 1286 1282 1287 - if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL && 1288 - test_bit(hwgpio, priv->watched_lines)) 1283 + gpio_desc_to_lineinfo(desc, &lineinfo); 1284 + 1285 + if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) 1286 + return -EFAULT; 1287 + return 0; 1288 + } else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) { 1289 + return linehandle_create(gdev, ip); 1290 + } else if (cmd == GPIO_GET_LINEEVENT_IOCTL) { 1291 + return lineevent_create(gdev, ip); 1292 + } else if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) { 1293 + struct gpioline_info lineinfo; 1294 + 1295 + if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) 1296 + return -EFAULT; 1297 + 1298 + desc = gpiochip_get_desc(gc, lineinfo.line_offset); 1299 + if (IS_ERR(desc)) 1300 + return PTR_ERR(desc); 1301 + 1302 + hwgpio = gpio_chip_hwgpio(desc); 1303 + 1304 + if (test_bit(hwgpio, priv->watched_lines)) 1289 1305 return -EBUSY; 1290 1306 1291 1307 gpio_desc_to_lineinfo(desc, &lineinfo); ··· 1313 1289 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) 1314 1290 return -EFAULT; 1315 1291 1316 - if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) 1317 - set_bit(hwgpio, priv->watched_lines); 1318 - 1292 + set_bit(hwgpio, priv->watched_lines); 1319 1293 return 0; 1320 - } else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) { 1321 - return linehandle_create(gdev, ip); 1322 - } else if (cmd == GPIO_GET_LINEEVENT_IOCTL) { 1323 - return lineevent_create(gdev, ip); 1324 1294 } else if (cmd == GPIO_GET_LINEINFO_UNWATCH_IOCTL) { 1325 1295 if (copy_from_user(&offset, ip, sizeof(offset))) 1326 1296 return -EFAULT; ··· 1556 1538 1557 1539 /* From this point, the .release() function cleans up gpio_device */ 1558 1540 gdev->dev.release = gpiodevice_release; 1559 - pr_debug("%s: registered GPIOs %d to %d on device: %s (%s)\n", 1560 - __func__, gdev->base, gdev->base + gdev->ngpio - 1, 1561 - dev_name(&gdev->dev), gdev->chip->label ? : "generic"); 1541 + dev_dbg(&gdev->dev, "registered GPIOs %d to %d on %s\n", gdev->base, 1542 + gdev->base + gdev->ngpio - 1, gdev->chip->label ? : "generic"); 1562 1543 1563 1544 return 0; 1564 1545 ··· 1573 1556 1574 1557 desc = gpiochip_get_desc(gc, hog->chip_hwnum); 1575 1558 if (IS_ERR(desc)) { 1576 - pr_err("%s: unable to get GPIO desc: %ld\n", 1577 - __func__, PTR_ERR(desc)); 1559 + chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__, 1560 + PTR_ERR(desc)); 1578 1561 return; 1579 1562 } 1580 1563 ··· 1583 1566 1584 1567 rv = gpiod_hog(desc, hog->line_name, hog->lflags, hog->dflags); 1585 1568 if (rv) 1586 - pr_err("%s: unable to hog GPIO line (%s:%u): %d\n", 1587 - __func__, gc->label, hog->chip_hwnum, rv); 1569 + gpiod_err(desc, "%s: unable to hog GPIO line (%s:%u): %d\n", 1570 + __func__, gc->label, hog->chip_hwnum, rv); 1588 1571 } 1589 1572 1590 1573 static void machine_gpiochip_add(struct gpio_chip *gc) ··· 1609 1592 list_for_each_entry(gdev, &gpio_devices, list) { 1610 1593 ret = gpiochip_setup_dev(gdev); 1611 1594 if (ret) 1612 - pr_err("%s: Failed to initialize gpio device (%d)\n", 1613 - dev_name(&gdev->dev), ret); 1595 + dev_err(&gdev->dev, 1596 + "Failed to initialize gpio device (%d)\n", ret); 1614 1597 } 1615 1598 } 1616 1599 ··· 2478 2461 gpiochip_relres_irq(gc, d->hwirq); 2479 2462 } 2480 2463 2464 + static void gpiochip_irq_mask(struct irq_data *d) 2465 + { 2466 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2467 + 2468 + if (gc->irq.irq_mask) 2469 + gc->irq.irq_mask(d); 2470 + gpiochip_disable_irq(gc, d->hwirq); 2471 + } 2472 + 2473 + static void gpiochip_irq_unmask(struct irq_data *d) 2474 + { 2475 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2476 + 2477 + gpiochip_enable_irq(gc, d->hwirq); 2478 + if (gc->irq.irq_unmask) 2479 + gc->irq.irq_unmask(d); 2480 + } 2481 + 2481 2482 static void gpiochip_irq_enable(struct irq_data *d) 2482 2483 { 2483 2484 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2484 2485 2485 2486 gpiochip_enable_irq(gc, d->hwirq); 2486 - if (gc->irq.irq_enable) 2487 - gc->irq.irq_enable(d); 2488 - else 2489 - gc->irq.chip->irq_unmask(d); 2487 + gc->irq.irq_enable(d); 2490 2488 } 2491 2489 2492 2490 static void gpiochip_irq_disable(struct irq_data *d) 2493 2491 { 2494 2492 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2495 2493 2496 - /* 2497 - * Since we override .irq_disable() we need to mimic the 2498 - * behaviour of __irq_disable() in irq/chip.c. 2499 - * First call .irq_disable() if it exists, else mimic the 2500 - * behaviour of mask_irq() which calls .irq_mask() if 2501 - * it exists. 2502 - */ 2503 - if (gc->irq.irq_disable) 2504 - gc->irq.irq_disable(d); 2505 - else if (gc->irq.chip->irq_mask) 2506 - gc->irq.chip->irq_mask(d); 2494 + gc->irq.irq_disable(d); 2507 2495 gpiochip_disable_irq(gc, d->hwirq); 2508 2496 } 2509 2497 ··· 2533 2511 "detected irqchip that is shared with multiple gpiochips: please fix the driver.\n"); 2534 2512 return; 2535 2513 } 2536 - gc->irq.irq_enable = irqchip->irq_enable; 2537 - gc->irq.irq_disable = irqchip->irq_disable; 2538 - irqchip->irq_enable = gpiochip_irq_enable; 2539 - irqchip->irq_disable = gpiochip_irq_disable; 2514 + 2515 + if (irqchip->irq_disable) { 2516 + gc->irq.irq_disable = irqchip->irq_disable; 2517 + irqchip->irq_disable = gpiochip_irq_disable; 2518 + } else { 2519 + gc->irq.irq_mask = irqchip->irq_mask; 2520 + irqchip->irq_mask = gpiochip_irq_mask; 2521 + } 2522 + 2523 + if (irqchip->irq_enable) { 2524 + gc->irq.irq_enable = irqchip->irq_enable; 2525 + irqchip->irq_enable = gpiochip_irq_enable; 2526 + } else { 2527 + gc->irq.irq_unmask = irqchip->irq_unmask; 2528 + irqchip->irq_unmask = gpiochip_irq_unmask; 2529 + } 2540 2530 } 2541 2531 2542 2532 /** ··· 2736 2702 return -EINVAL; 2737 2703 2738 2704 if (!gc->parent) { 2739 - pr_err("missing gpiochip .dev parent pointer\n"); 2705 + chip_err(gc, "missing gpiochip .dev parent pointer\n"); 2740 2706 return -EINVAL; 2741 2707 } 2742 2708 gc->irq.threaded = threaded; ··· 2785 2751 return 0; 2786 2752 } 2787 2753 EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key); 2754 + 2755 + /** 2756 + * gpiochip_irqchip_add_domain() - adds an irqdomain to a gpiochip 2757 + * @gc: the gpiochip to add the irqchip to 2758 + * @domain: the irqdomain to add to the gpiochip 2759 + * 2760 + * This function adds an IRQ domain to the gpiochip. 2761 + */ 2762 + int gpiochip_irqchip_add_domain(struct gpio_chip *gc, 2763 + struct irq_domain *domain) 2764 + { 2765 + if (!domain) 2766 + return -EINVAL; 2767 + 2768 + gc->to_irq = gpiochip_to_irq; 2769 + gc->irq.domain = domain; 2770 + 2771 + return 0; 2772 + } 2773 + EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_domain); 2788 2774 2789 2775 #else /* CONFIG_GPIOLIB_IRQCHIP */ 2790 2776 ··· 4707 4653 if (!table) 4708 4654 return desc; 4709 4655 4710 - for (p = &table->table[0]; p->chip_label; p++) { 4656 + for (p = &table->table[0]; p->key; p++) { 4711 4657 struct gpio_chip *gc; 4712 4658 4713 4659 /* idx must always match exactly */ ··· 4718 4664 if (p->con_id && (!con_id || strcmp(p->con_id, con_id))) 4719 4665 continue; 4720 4666 4721 - gc = find_chip_by_name(p->chip_label); 4667 + if (p->chip_hwnum == U16_MAX) { 4668 + desc = gpio_name_to_desc(p->key); 4669 + if (desc) { 4670 + *flags = p->flags; 4671 + return desc; 4672 + } 4673 + 4674 + dev_warn(dev, "cannot find GPIO line %s, deferring\n", 4675 + p->key); 4676 + return ERR_PTR(-EPROBE_DEFER); 4677 + } 4678 + 4679 + gc = find_chip_by_name(p->key); 4722 4680 4723 4681 if (!gc) { 4724 4682 /* 4725 4683 * As the lookup table indicates a chip with 4726 - * p->chip_label should exist, assume it may 4684 + * p->key should exist, assume it may 4727 4685 * still appear later and let the interested 4728 4686 * consumer be probed again or let the Deferred 4729 4687 * Probe infrastructure handle the error. 4730 4688 */ 4731 4689 dev_warn(dev, "cannot find GPIO chip %s, deferring\n", 4732 - p->chip_label); 4690 + p->key); 4733 4691 return ERR_PTR(-EPROBE_DEFER); 4734 4692 } 4735 4693 ··· 4772 4706 if (!table) 4773 4707 return -ENOENT; 4774 4708 4775 - for (p = &table->table[0]; p->chip_label; p++) { 4709 + for (p = &table->table[0]; p->key; p++) { 4776 4710 if ((con_id && p->con_id && !strcmp(con_id, p->con_id)) || 4777 4711 (!con_id && !p->con_id)) 4778 4712 count++; ··· 4943 4877 4944 4878 /* No particular flag request, return here... */ 4945 4879 if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) { 4946 - pr_debug("no flags found for %s\n", con_id); 4880 + gpiod_dbg(desc, "no flags found for %s\n", con_id); 4947 4881 return 0; 4948 4882 } 4949 4883 ··· 5174 5108 /* Mark GPIO as hogged so it can be identified and removed later */ 5175 5109 set_bit(FLAG_IS_HOGGED, &desc->flags); 5176 5110 5177 - pr_info("GPIO line %d (%s) hogged as %s%s\n", 5178 - desc_to_gpio(desc), name, 5111 + gpiod_info(desc, "hogged as %s%s\n", 5179 5112 (dflags & GPIOD_FLAGS_BIT_DIR_OUT) ? "output" : "input", 5180 5113 (dflags & GPIOD_FLAGS_BIT_DIR_OUT) ? 5181 5114 (dflags & GPIOD_FLAGS_BIT_DIR_VAL) ? "/high" : "/low" : "");
+13 -14
drivers/gpio/gpiolib.h
··· 81 81 unsigned long invert_mask[]; 82 82 }; 83 83 84 - struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, 85 - unsigned int hwnum); 84 + struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); 86 85 int gpiod_get_array_value_complex(bool raw, bool can_sleep, 87 86 unsigned int array_size, 88 87 struct gpio_desc **desc_array, ··· 162 163 163 164 /* With chip prefix */ 164 165 165 - #define chip_emerg(chip, fmt, ...) \ 166 - dev_emerg(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) 167 - #define chip_crit(chip, fmt, ...) \ 168 - dev_crit(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) 169 - #define chip_err(chip, fmt, ...) \ 170 - dev_err(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) 171 - #define chip_warn(chip, fmt, ...) \ 172 - dev_warn(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) 173 - #define chip_info(chip, fmt, ...) \ 174 - dev_info(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) 175 - #define chip_dbg(chip, fmt, ...) \ 176 - dev_dbg(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) 166 + #define chip_emerg(gc, fmt, ...) \ 167 + dev_emerg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 168 + #define chip_crit(gc, fmt, ...) \ 169 + dev_crit(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 170 + #define chip_err(gc, fmt, ...) \ 171 + dev_err(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 172 + #define chip_warn(gc, fmt, ...) \ 173 + dev_warn(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 174 + #define chip_info(gc, fmt, ...) \ 175 + dev_info(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 176 + #define chip_dbg(gc, fmt, ...) \ 177 + dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 177 178 178 179 #ifdef CONFIG_GPIO_SYSFS 179 180
+3 -3
drivers/i2c/busses/i2c-i801.c
··· 1439 1439 return -ENOMEM; 1440 1440 lookup->dev_id = "i2c-mux-gpio"; 1441 1441 for (i = 0; i < mux_config->n_gpios; i++) { 1442 - lookup->table[i].chip_label = mux_config->gpio_chip; 1443 - lookup->table[i].chip_hwnum = mux_config->gpios[i]; 1444 - lookup->table[i].con_id = "mux"; 1442 + lookup->table[i] = (struct gpiod_lookup) 1443 + GPIO_LOOKUP(mux_config->gpio_chip, 1444 + mux_config->gpios[i], "mux", 0); 1445 1445 } 1446 1446 gpiod_add_lookup_table(lookup); 1447 1447 priv->lookup = lookup;
-1
drivers/mfd/intel_quark_i2c_gpio.c
··· 216 216 pdata->properties->ngpio = INTEL_QUARK_MFD_NGPIO; 217 217 pdata->properties->gpio_base = INTEL_QUARK_MFD_GPIO_BASE; 218 218 pdata->properties->irq[0] = pdev->irq; 219 - pdata->properties->has_irq = true; 220 219 pdata->properties->irq_shared = true; 221 220 222 221 cell->platform_data = pdata;
+8 -16
drivers/mfd/sm501.c
··· 1145 1145 return -ENOMEM; 1146 1146 1147 1147 lookup->dev_id = "i2c-gpio"; 1148 - if (iic->pin_sda < 32) 1149 - lookup->table[0].chip_label = "SM501-LOW"; 1150 - else 1151 - lookup->table[0].chip_label = "SM501-HIGH"; 1152 - lookup->table[0].chip_hwnum = iic->pin_sda % 32; 1153 - lookup->table[0].con_id = NULL; 1154 - lookup->table[0].idx = 0; 1155 - lookup->table[0].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; 1156 - if (iic->pin_scl < 32) 1157 - lookup->table[1].chip_label = "SM501-LOW"; 1158 - else 1159 - lookup->table[1].chip_label = "SM501-HIGH"; 1160 - lookup->table[1].chip_hwnum = iic->pin_scl % 32; 1161 - lookup->table[1].con_id = NULL; 1162 - lookup->table[1].idx = 1; 1163 - lookup->table[1].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; 1148 + lookup->table[0] = (struct gpiod_lookup) 1149 + GPIO_LOOKUP_IDX(iic->pin_sda < 32 ? "SM501-LOW" : "SM501-HIGH", 1150 + iic->pin_sda % 32, NULL, 0, 1151 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN); 1152 + lookup->table[1] = (struct gpiod_lookup) 1153 + GPIO_LOOKUP_IDX(iic->pin_scl < 32 ? "SM501-LOW" : "SM501-HIGH", 1154 + iic->pin_scl % 32, NULL, 1, 1155 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN); 1164 1156 gpiod_add_lookup_table(lookup); 1165 1157 1166 1158 icd = dev_get_platdata(&pdev->dev);
+32 -16
include/linux/gpio/driver.h
··· 253 253 * Store old irq_chip irq_disable callback 254 254 */ 255 255 void (*irq_disable)(struct irq_data *data); 256 + /** 257 + * @irq_unmask: 258 + * 259 + * Store old irq_chip irq_unmask callback 260 + */ 261 + void (*irq_unmask)(struct irq_data *data); 262 + 263 + /** 264 + * @irq_mask: 265 + * 266 + * Store old irq_chip irq_mask callback 267 + */ 268 + void (*irq_mask)(struct irq_data *data); 256 269 }; 257 270 258 271 /** ··· 280 267 * @free: optional hook for chip-specific deactivation, such as 281 268 * disabling module power and clock; may sleep 282 269 * @get_direction: returns direction for signal "offset", 0=out, 1=in, 283 - * (same as GPIOF_DIR_XXX), or negative error. 284 - * It is recommended to always implement this function, even on 285 - * input-only or output-only gpio chips. 270 + * (same as GPIO_LINE_DIRECTION_OUT / GPIO_LINE_DIRECTION_IN), 271 + * or negative error. It is recommended to always implement this 272 + * function, even on input-only or output-only gpio chips. 286 273 * @direction_input: configures signal "offset" as input, or returns error 287 274 * This can be omitted on input-only or output-only gpio chips. 288 275 * @direction_output: configures signal "offset" as output, or returns error ··· 362 349 struct module *owner; 363 350 364 351 int (*request)(struct gpio_chip *gc, 365 - unsigned offset); 352 + unsigned int offset); 366 353 void (*free)(struct gpio_chip *gc, 367 - unsigned offset); 354 + unsigned int offset); 368 355 int (*get_direction)(struct gpio_chip *gc, 369 - unsigned offset); 356 + unsigned int offset); 370 357 int (*direction_input)(struct gpio_chip *gc, 371 - unsigned offset); 358 + unsigned int offset); 372 359 int (*direction_output)(struct gpio_chip *gc, 373 - unsigned offset, int value); 360 + unsigned int offset, int value); 374 361 int (*get)(struct gpio_chip *gc, 375 - unsigned offset); 362 + unsigned int offset); 376 363 int (*get_multiple)(struct gpio_chip *gc, 377 364 unsigned long *mask, 378 365 unsigned long *bits); 379 366 void (*set)(struct gpio_chip *gc, 380 - unsigned offset, int value); 367 + unsigned int offset, int value); 381 368 void (*set_multiple)(struct gpio_chip *gc, 382 369 unsigned long *mask, 383 370 unsigned long *bits); 384 371 int (*set_config)(struct gpio_chip *gc, 385 - unsigned offset, 372 + unsigned int offset, 386 373 unsigned long config); 387 374 int (*to_irq)(struct gpio_chip *gc, 388 - unsigned offset); 375 + unsigned int offset); 389 376 390 377 void (*dbg_show)(struct seq_file *s, 391 378 struct gpio_chip *gc); ··· 472 459 }; 473 460 474 461 extern const char *gpiochip_is_requested(struct gpio_chip *gc, 475 - unsigned offset); 462 + unsigned int offset); 476 463 477 464 /* add/remove chips */ 478 465 extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, ··· 612 599 bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, 613 600 unsigned int offset); 614 601 602 + int gpiochip_irqchip_add_domain(struct gpio_chip *gc, 603 + struct irq_domain *domain); 604 + 615 605 #ifdef CONFIG_LOCKDEP 616 606 617 607 /* ··· 673 657 } 674 658 #endif /* CONFIG_LOCKDEP */ 675 659 676 - int gpiochip_generic_request(struct gpio_chip *gc, unsigned offset); 677 - void gpiochip_generic_free(struct gpio_chip *gc, unsigned offset); 678 - int gpiochip_generic_config(struct gpio_chip *gc, unsigned offset, 660 + int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset); 661 + void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset); 662 + int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset, 679 663 unsigned long config); 680 664 681 665 /**
+10 -7
include/linux/gpio/machine.h
··· 20 20 21 21 /** 22 22 * struct gpiod_lookup - lookup table 23 - * @chip_label: name of the chip the GPIO belongs to 24 - * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 23 + * @key: either the name of the chip the GPIO belongs to, or the GPIO line name 24 + * Note that GPIO line names are not guaranteed to be globally unique, 25 + * so this will use the first match found! 26 + * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO, or 27 + * U16_MAX to indicate that @key is a GPIO line name 25 28 * @con_id: name of the GPIO from the device's point of view 26 29 * @idx: index of the GPIO in case several GPIOs share the same name 27 30 * @flags: bitmask of gpio_lookup_flags GPIO_* values ··· 33 30 * functions using platform data. 34 31 */ 35 32 struct gpiod_lookup { 36 - const char *chip_label; 33 + const char *key; 37 34 u16 chip_hwnum; 38 35 const char *con_id; 39 36 unsigned int idx; ··· 66 63 /* 67 64 * Simple definition of a single GPIO under a con_id 68 65 */ 69 - #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \ 70 - GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags) 66 + #define GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags) \ 67 + GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, 0, _flags) 71 68 72 69 /* 73 70 * Use this macro if you need to have several GPIOs under the same con_id. 74 71 * Each GPIO needs to use a different index and can be accessed using 75 72 * gpiod_get_index() 76 73 */ 77 - #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \ 74 + #define GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, _idx, _flags) \ 78 75 { \ 79 - .chip_label = _chip_label, \ 76 + .key = _key, \ 80 77 .chip_hwnum = _chip_hwnum, \ 81 78 .con_id = _con_id, \ 82 79 .idx = _idx, \
+86
include/linux/gpio/regmap.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + #ifndef _LINUX_GPIO_REGMAP_H 4 + #define _LINUX_GPIO_REGMAP_H 5 + 6 + struct device; 7 + struct gpio_regmap; 8 + struct irq_domain; 9 + struct regmap; 10 + 11 + #define GPIO_REGMAP_ADDR_ZERO ((unsigned long)(-1)) 12 + #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO) 13 + 14 + /** 15 + * struct gpio_regmap_config - Description of a generic regmap gpio_chip. 16 + * @parent: The parent device 17 + * @regmap: The regmap used to access the registers 18 + * given, the name of the device is used 19 + * @label: (Optional) Descriptive name for GPIO controller. 20 + * If not given, the name of the device is used. 21 + * @ngpio: Number of GPIOs 22 + * @names: (Optional) Array of names for gpios 23 + * @reg_dat_base: (Optional) (in) register base address 24 + * @reg_set_base: (Optional) set register base address 25 + * @reg_clr_base: (Optional) clear register base address 26 + * @reg_dir_in_base: (Optional) in setting register base address 27 + * @reg_dir_out_base: (Optional) out setting register base address 28 + * @reg_stride: (Optional) May be set if the registers (of the 29 + * same type, dat, set, etc) are not consecutive. 30 + * @ngpio_per_reg: Number of GPIOs per register 31 + * @irq_domain: (Optional) IRQ domain if the controller is 32 + * interrupt-capable 33 + * @reg_mask_xlate: (Optional) Translates base address and GPIO 34 + * offset to a register/bitmask pair. If not 35 + * given the default gpio_regmap_simple_xlate() 36 + * is used. 37 + * 38 + * The ->reg_mask_xlate translates a given base address and GPIO offset to 39 + * register and mask pair. The base address is one of the given register 40 + * base addresses in this structure. 41 + * 42 + * Although all register base addresses are marked as optional, there are 43 + * several rules: 44 + * 1. if you only have @reg_dat_base set, then it is input-only 45 + * 2. if you only have @reg_set_base set, then it is output-only 46 + * 3. if you have either @reg_dir_in_base or @reg_dir_out_base set, then 47 + * you have to set both @reg_dat_base and @reg_set_base 48 + * 4. if you have @reg_set_base set, you may also set @reg_clr_base to have 49 + * two different registers for setting and clearing the output. This is 50 + * also valid for the output-only case. 51 + * 5. @reg_dir_in_base and @reg_dir_out_base are exclusive; is there really 52 + * hardware which has redundant registers? 53 + * 54 + * Note: All base addresses may have the special value %GPIO_REGMAP_ADDR_ZERO 55 + * which forces the address to the value 0. 56 + */ 57 + struct gpio_regmap_config { 58 + struct device *parent; 59 + struct regmap *regmap; 60 + 61 + const char *label; 62 + int ngpio; 63 + const char *const *names; 64 + 65 + unsigned int reg_dat_base; 66 + unsigned int reg_set_base; 67 + unsigned int reg_clr_base; 68 + unsigned int reg_dir_in_base; 69 + unsigned int reg_dir_out_base; 70 + int reg_stride; 71 + int ngpio_per_reg; 72 + struct irq_domain *irq_domain; 73 + 74 + int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, 75 + unsigned int offset, unsigned int *reg, 76 + unsigned int *mask); 77 + }; 78 + 79 + struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config); 80 + void gpio_regmap_unregister(struct gpio_regmap *gpio); 81 + struct gpio_regmap *devm_gpio_regmap_register(struct device *dev, 82 + const struct gpio_regmap_config *config); 83 + void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data); 84 + void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio); 85 + 86 + #endif /* _LINUX_GPIO_REGMAP_H */
-1
include/linux/platform_data/gpio-dwapb.h
··· 12 12 unsigned int ngpio; 13 13 unsigned int gpio_base; 14 14 int irq[32]; 15 - bool has_irq; 16 15 bool irq_shared; 17 16 }; 18 17
+12
tools/gpio/lsgpio.c
··· 49 49 .name = "open-source", 50 50 .mask = GPIOLINE_FLAG_OPEN_SOURCE, 51 51 }, 52 + { 53 + .name = "pull-up", 54 + .mask = GPIOLINE_FLAG_BIAS_PULL_UP, 55 + }, 56 + { 57 + .name = "pull-down", 58 + .mask = GPIOLINE_FLAG_BIAS_PULL_DOWN, 59 + }, 60 + { 61 + .name = "bias-disabled", 62 + .mask = GPIOLINE_FLAG_BIAS_DISABLE, 63 + }, 52 64 }; 53 65 54 66 void print_flags(unsigned long flags)