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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'gpio-updates-for-v7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio updates from Bartosz Golaszewski:
"For this merge window we have two new drivers: support for
GPIO-signalled ACPI events on Intel platforms and a generic
GPIO-over-pinctrl driver using the ARM SCMI protocol for
controlling pins.

Several things have been reworked in GPIO core: we unduplicated GPIO
hog handling, reduced the number of SRCU locks and dereferences,
improved support for software-node-based lookup and removed more
legacy code after converting remaining users to modern alternatives.

There's also a number of driver reworks and refactoring, documentation
updates, some bug-fixes and new tests.

GPIO core:
- defer probe on software node lookups when the remote software node
exists but has not been registered as a firmware node yet
- unify GPIO hog handling by moving code duplicated in OF and ACPI
modules into GPIO core and allow setting up hogs with software
nodes
- allow matching GPIO controllers by secondary firmware node if
matching by primary does not succeed
- demote deferral warnings to debug level as they are quite normal
when using software nodes which don't support fw_devlink yet
- disable the legacy GPIO character device uAPI v1 supprt in Kconfig
by default
- rework several core functions in preparation for the upcoming
Revocable helper library for protecting resources against sudden
removal, this reduces the number of SRCU dereferences in GPIO core
- simplify file descriptor logic in GPIO character device code by
using FD_PREPARE()
- introduce a header defining symbols used by both GPIO consumers and
providers to avoid having to include provider-specific headers from
drivers which only consume GPIOs
- replace snprintf() with strscpy() where formatting is not required

New drivers:
- add the gpio-by-pinctrl generic driver using the ARM SCMI protocol
to control GPIOs (along with SCMI changes pulled from the pinctrl
tree)
- add a driver providing support for handling of platform events via
GPIO-signalled ACPI events (used on Intel Nova Lake and later
platforms)

Driver changes:
- extend the gpio-kempld driver with support for more recent models,
interrupts and setting/getting multiple values at once
- improve interrupt handling in gpio-brcmstb
- add support for multi-SoC systems in gpio-tegra186
- make sure we return correct values from the .get() callbacks in
several GPIO drivers by normalizing any values other than 0, 1 or
negative error numbers
- use flexible arrays in several drivers to reduce the number of
required memory allocations
- simplify synchronous waiting for virtual drivers to probe and
remove the dedicated, a bit overengineered helper library
dev-sync-probe
- remove unneeded Kconfig dependencies on OF_GPIO in several drivers
and subsystems
- convert the two remaining users of of_get_named_gpio() to using
GPIO descriptors and remove the (no longer used) function along
with the header that declares it
- add missing includes in gpio-mmio
- shrink and simplify code in gpio-max732x by using guard(mutex)
- remove duplicated code handling the 'ngpios' property from
gpio-ts4800, it's already handled in GPIO core
- use correct variable type in gpio-aspeed
- add support for a new model in gpio-realtek-otto
- allow to specify the active-low setting of simulated hogs over the
configfs interface (in addition to existing devicetree support) in
gpio-sim

Bug fixes:
- clear the OF_POPULATED flag on hog nodes in GPIO chip remove path
on OF systems
- fix resource leaks in error path in gpiochip_add_data_with_key()
- drop redundant device reference in gpio-mpsse

Tests:
- add selftests for use-after-free cases in GPIO character device
code

DT bindings:
- add a DT binding document for SCMI based, gpio-over-pinctrl devices
- fix interrupt description in microchip,mpfs-gpio
- add new compatible for gpio-realtek-otto
- describe the resets of the mpfs-gpio controller
- fix maintainer's email in gpio-delay bindings
- remove the binding document for cavium,thunder-8890 as the
corresponding device is bound over PCI and not firmware nodes

Documentation:
- update the recommended way of converting legacy boards to using
software nodes for GPIO description
- describe GPIO line value semantics
- misc updates to kerneldocs

Misc:
- convert OMAP1 ams-delta board to using GPIO hogs described with
software nodes"

* tag 'gpio-updates-for-v7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (79 commits)
gpio: swnode: defer probe on references to unregistered software nodes
dt-bindings: gpio: cavium,thunder-8890: Remove DT binding
Documentation: gpio: update the preferred method for using software node lookup
gpio: gpio-by-pinctrl: s/used to do/is used to do/
gpio: aspeed: fix unsigned long int declaration
gpio: rockchip: convert to dynamic GPIO base allocation
gpio: remove dev-sync-probe
gpio: virtuser: stop using dev-sync-probe
gpio: aggregator: stop using dev-sync-probe
gpio: sim: stop using dev-sync-probe
gpio: Add Intel Nova Lake ACPI GPIO events driver
gpiolib: Make deferral warnings debug messages
gpiolib: fix hogs with multiple lines
gpio: fix up CONFIG_OF dependencies
gpio: gpio-by-pinctrl: add pinctrl based generic GPIO driver
gpio: dt-bindings: Add GPIO on top of generic pin control
firmware: arm_scmi: Allow PINCTRL_REQUEST to return EOPNOTSUPP
pinctrl: scmi: ignore PIN_CONFIG_PERSIST_STATE
pinctrl: scmi: Delete PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS support
pinctrl: scmi: Add SCMI_PIN_INPUT_VALUE
...

+2078 -1278
+1 -1
Documentation/devicetree/bindings/gpio/gpio-delay.yaml
··· 7 7 title: GPIO delay controller 8 8 9 9 maintainers: 10 - - Alexander Stein <linux@ew.tq-group.com> 10 + - Alexander Stein <alexander.stein@ew.tq-group.com> 11 11 12 12 description: | 13 13 This binding describes an electrical setup where setting an GPIO output
-27
Documentation/devicetree/bindings/gpio/gpio-thunderx.txt
··· 1 - Cavium ThunderX/OCTEON-TX GPIO controller bindings 2 - 3 - Required Properties: 4 - - reg: The controller bus address. 5 - - gpio-controller: Marks the device node as a GPIO controller. 6 - - #gpio-cells: Must be 2. 7 - - First cell is the GPIO pin number relative to the controller. 8 - - Second cell is a standard generic flag bitfield as described in gpio.txt. 9 - 10 - Optional Properties: 11 - - compatible: "cavium,thunder-8890-gpio", unused as PCI driver binding is used. 12 - - interrupt-controller: Marks the device node as an interrupt controller. 13 - - #interrupt-cells: Must be present and have value of 2 if 14 - "interrupt-controller" is present. 15 - - First cell is the GPIO pin number relative to the controller. 16 - - Second cell is triggering flags as defined in interrupts.txt. 17 - 18 - Example: 19 - 20 - gpio_6_0: gpio@6,0 { 21 - compatible = "cavium,thunder-8890-gpio"; 22 - reg = <0x3000 0 0 0 0>; /* DEVFN = 0x30 (6:0) */ 23 - gpio-controller; 24 - #gpio-cells = <2>; 25 - interrupt-controller; 26 - #interrupt-cells = <2>; 27 - };
+18 -9
Documentation/devicetree/bindings/gpio/microchip,mpfs-gpio.yaml
··· 33 33 clocks: 34 34 maxItems: 1 35 35 36 + resets: 37 + maxItems: 1 38 + 36 39 "#gpio-cells": 37 40 const: 2 38 41 ··· 65 62 contains: 66 63 const: microchip,mpfs-gpio 67 64 then: 65 + properties: 66 + ngpios: 67 + enum: [14, 24, 32] 68 + interrupts: 69 + minItems: 14 68 70 required: 69 71 - interrupts 70 72 - "#interrupt-cells" ··· 90 82 compatible = "microchip,mpfs-gpio"; 91 83 reg = <0x20122000 0x1000>; 92 84 clocks = <&clkcfg 25>; 93 - interrupt-parent = <&plic>; 85 + interrupt-parent = <&irqmux>; 94 86 gpio-controller; 95 87 #gpio-cells = <2>; 88 + ngpios = <32>; 96 89 interrupt-controller; 97 90 #interrupt-cells = <2>; 98 - interrupts = <53>, <53>, <53>, <53>, 99 - <53>, <53>, <53>, <53>, 100 - <53>, <53>, <53>, <53>, 101 - <53>, <53>, <53>, <53>, 102 - <53>, <53>, <53>, <53>, 103 - <53>, <53>, <53>, <53>, 104 - <53>, <53>, <53>, <53>, 105 - <53>, <53>, <53>, <53>; 91 + interrupts = <64>, <65>, <66>, <67>, 92 + <68>, <69>, <70>, <71>, 93 + <72>, <73>, <74>, <75>, 94 + <76>, <77>, <78>, <79>, 95 + <80>, <81>, <82>, <83>, 96 + <84>, <85>, <86>, <87>, 97 + <88>, <89>, <90>, <91>, 98 + <92>, <93>, <94>, <95>; 106 99 }; 107 100 ...
+59
Documentation/devicetree/bindings/gpio/pin-control-gpio.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/pin-control-gpio.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Pin control based generic GPIO controller 8 + 9 + description: 10 + The pin control-based GPIO will facilitate a pin controller's ability 11 + to drive electric lines high/low and other generic properties of a 12 + pin controller to perform general-purpose one-bit binary I/O. 13 + 14 + maintainers: 15 + - Dan Carpenter <dan.carpenter@linaro.org> 16 + 17 + properties: 18 + compatible: 19 + const: scmi-pinctrl-gpio 20 + 21 + gpio-controller: true 22 + 23 + "#gpio-cells": 24 + const: 2 25 + 26 + gpio-line-names: true 27 + 28 + gpio-ranges: true 29 + 30 + ngpios: true 31 + 32 + patternProperties: 33 + "^.+-hog(-[0-9]+)?$": 34 + type: object 35 + 36 + required: 37 + - gpio-hog 38 + 39 + required: 40 + - compatible 41 + - gpio-controller 42 + - "#gpio-cells" 43 + - gpio-ranges 44 + - ngpios 45 + 46 + additionalProperties: false 47 + 48 + examples: 49 + - | 50 + gpio { 51 + compatible = "scmi-pinctrl-gpio"; 52 + gpio-controller; 53 + #gpio-cells = <2>; 54 + ngpios = <4>; 55 + gpio-line-names = "gpio_5_17", "gpio_5_20", "gpio_5_22", "gpio_2_1"; 56 + gpio-ranges = <&scmi_pinctrl 0 30 4>; 57 + pinctrl-names = "default"; 58 + pinctrl-0 = <&keys_pins>; 59 + };
+1
Documentation/devicetree/bindings/gpio/realtek,otto-gpio.yaml
··· 30 30 - realtek,rtl8390-gpio 31 31 - realtek,rtl9300-gpio 32 32 - realtek,rtl9310-gpio 33 + - realtek,rtl9607-gpio 33 34 - const: realtek,otto-gpio 34 35 35 36 reg: true
+18 -21
Documentation/driver-api/gpio/board.rst
··· 108 108 consumer device. It allows consumers to use regular gpiolib APIs, such as 109 109 gpiod_get(), gpiod_get_optional(). 110 110 111 - The software node representing a GPIO controller need not be attached to the 112 - GPIO controller device. The only requirement is that the node must be 113 - registered and its name must match the GPIO controller's label. 111 + The software node representing a GPIO controller must be attached to the 112 + GPIO controller device - either as the primary or the secondary firmware node. 114 113 115 114 For example, here is how to describe a single GPIO-connected LED. This is an 116 115 alternative to using platform_data on legacy systems. ··· 121 122 #include <linux/gpio/property.h> 122 123 123 124 /* 124 - * 1. Define a node for the GPIO controller. Its .name must match the 125 - * controller's label. 125 + * 1. Define a node for the GPIO controller. 126 126 */ 127 127 static const struct software_node gpio_controller_node = { 128 128 .name = "gpio-foo", ··· 150 152 NULL 151 153 }; 152 154 software_node_register_node_group(swnodes); 155 + 156 + /* 157 + * 5. Attach the GPIO controller's software node to the device and 158 + * register it. 159 + */ 160 + static void gpio_foo_register(void) 161 + { 162 + struct platform_device_info pdev_info = { 163 + .name = "gpio-foo", 164 + .id = PLATFORM_DEVID_NONE, 165 + .swnode = &gpio_controller_node 166 + }; 167 + 168 + platform_device_register_full(&pdev_info); 169 + } 153 170 154 171 // Then register a platform_device for "leds-gpio" and associate 155 172 // it with &led_device_swnode via .fwnode. ··· 251 238 252 239 A set of functions such as gpiod_set_value() is available to work with 253 240 the new descriptor-oriented interface. 254 - 255 - Boards using platform data can also hog GPIO lines by defining GPIO hog tables. 256 - 257 - .. code-block:: c 258 - 259 - struct gpiod_hog gpio_hog_table[] = { 260 - GPIO_HOG("gpio.0", 10, "foo", GPIO_ACTIVE_LOW, GPIOD_OUT_HIGH), 261 - { } 262 - }; 263 - 264 - And the table can be added to the board code as follows:: 265 - 266 - gpiod_add_hogs(gpio_hog_table); 267 - 268 - The line will be hogged as soon as the gpiochip is created or - in case the 269 - chip was created earlier - when the hog table is registered. 270 241 271 242 Arrays of pins 272 243 --------------
+27
Documentation/driver-api/gpio/driver.rst
··· 87 87 contexts). Normally this should not be required. 88 88 89 89 90 + GPIO level semantics 91 + -------------------- 92 + 93 + The gpip_chip .get/set[_multiple]() line values are clamped to the boolean 94 + space [0, 1], low level or high level. 95 + 96 + Low and high values are defined as physical low on the line in/out to the 97 + connector such as a physical pad, pin or rail. 98 + 99 + The GPIO library has internal logic to handle lines that are active low, such 100 + as indicated by overstrike or #name in a schematic, and the driver should not 101 + try to second-guess the logic value of a line. 102 + 103 + The way GPIO values are handled by the consumers is that the library present 104 + the *logical* value to the consumer. A line is *asserted* if its *logical* 105 + value is 1, and *de-asserted* if its logical value is 0. If inversion is 106 + required, this is handled by gpiolib and configured using hardware descriptions 107 + such as device tree or ACPI that can clearly indicate if a line is active 108 + high or low. 109 + 110 + Since electronics commonly insert inverters as driving stages or protection 111 + buffers in front of a GPIO line it is necessary that this semantic is part 112 + of the hardware description, so that consumers such as kernel drivers need 113 + not worry about this, and can for example assert a RESET line tied to a GPIO 114 + pin by setting it to logic 1 even if it is physically active low. 115 + 116 + 90 117 GPIO electrical configuration 91 118 ----------------------------- 92 119
+27 -9
Documentation/driver-api/gpio/legacy-boards.rst
··· 36 36 When using software nodes to describe GPIO connections, the following 37 37 requirements must be met for the GPIO core to correctly resolve the reference: 38 38 39 - 1. **The GPIO controller's software node "name" must match the controller's 40 - "label".** The gpiolib core uses this name to find the corresponding 41 - struct gpio_chip at runtime. 42 - This software node has to be registered, but need not be attached to the 43 - device representing the GPIO controller that is providing the GPIO in 44 - question. It may be left as a "free floating" node. 39 + 1. **The GPIO controller's software node must be registered and attached to 40 + the controller's ``struct device`` either as its primary or secondary 41 + firmware node.** The gpiolib core uses the address of the firmware node to 42 + find the corresponding ``struct gpio_chip`` at runtime. 45 43 46 44 2. **The GPIO property must be a reference.** The ``PROPERTY_ENTRY_GPIO()`` 47 45 macro handles this as it is an alias for ``PROPERTY_ENTRY_REF()``. ··· 119 121 /* Device registration */ 120 122 static int __init myboard_init(void) 121 123 { 124 + struct platform_device_info pdev_info = { 125 + .name = MYBOARD_GPIO_CONTROLLER, 126 + .id = PLATFORM_DEVID_NONE, 127 + .swnode = &gpio_controller_node 128 + }; 129 + 122 130 gpiod_add_lookup_table(&myboard_leds_gpios); 123 131 gpiod_add_lookup_table(&myboard_buttons_gpios); 124 132 133 + platform_device_register_full(&pdev_info); 125 134 platform_device_register_data(NULL, "leds-gpio", -1, 126 135 &myboard_leds_pdata, sizeof(myboard_leds_pdata)); 127 136 platform_device_register_data(NULL, "gpio-keys", -1, 128 - &myboard_buttons_pdata, sizeof(myboard_buttons_pdata)); 137 + &myboard_buttons_pdata, 138 + sizeof(myboard_buttons_pdata)); 129 139 130 140 return 0; 131 141 } ··· 147 141 *************************************** 148 142 149 143 First, define a software node that represents the GPIO controller that the 150 - LEDs and buttons are connected to. The ``name`` of this node must match the 151 - name of the driver for the GPIO controller (e.g., "gpio-foo"). 144 + LEDs and buttons are connected to. The ``name`` of this node is optional. 152 145 153 146 .. code-block:: c 154 147 ··· 263 258 return error; 264 259 265 260 memset(&pdev_info, 0, sizeof(pdev_info)); 261 + pdev_info.name = MYBOARD_GPIO_CONTROLLER; 262 + pdev_info.id = PLATFORM_DEVID_NONE; 263 + pdev_info.swnode = &myboard_gpio_controller_node; 264 + gpio_pdev = platform_device_register_full(&pdev_info); 265 + if (IS_ERR(gpio_pdev)) { 266 + error = PTR_ERR(gpio_pdev); 267 + goto err_unregister_nodes; 268 + } 269 + 270 + memset(&pdev_info, 0, sizeof(pdev_info)); 266 271 pdev_info.name = "leds-gpio"; 267 272 pdev_info.id = PLATFORM_DEVID_NONE; 268 273 pdev_info.fwnode = software_node_fwnode(&myboard_leds_node); 269 274 leds_pdev = platform_device_register_full(&pdev_info); 270 275 if (IS_ERR(leds_pdev)) { 271 276 error = PTR_ERR(leds_pdev); 277 + platform_device_unregister(gpio_pdev); 272 278 goto err_unregister_nodes; 273 279 } 274 280 ··· 290 274 keys_pdev = platform_device_register_full(&pdev_info); 291 275 if (IS_ERR(keys_pdev)) { 292 276 error = PTR_ERR(keys_pdev); 277 + platform_device_unregister(gpio_pdev); 293 278 platform_device_unregister(leds_pdev); 294 279 goto err_unregister_nodes; 295 280 } ··· 306 289 { 307 290 platform_device_unregister(keys_pdev); 308 291 platform_device_unregister(leds_pdev); 292 + platform_device_unregister(gpio_pdev); 309 293 software_node_unregister_node_group(myboard_swnodes); 310 294 } 311 295
+7 -1
MAINTAINERS
··· 10982 10982 F: include/dt-bindings/gpio/ 10983 10983 F: include/linux/gpio.h 10984 10984 F: include/linux/gpio/ 10985 - F: include/linux/of_gpio.h 10986 10985 K: (devm_)?gpio_(request|free|direction|get|set) 10987 10986 K: GPIOD_FLAGS_BIT_NONEXCLUSIVE 10988 10987 K: devm_gpiod_unhinge ··· 12870 12871 F: drivers/gpio/gpio-sodaville.c 12871 12872 F: drivers/gpio/gpio-tangier.c 12872 12873 F: drivers/gpio/gpio-tangier.h 12874 + 12875 + INTEL GPIO GPE DRIVER 12876 + M: Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com> 12877 + R: Mika Westerberg <westeri@kernel.org> 12878 + L: linux-gpio@vger.kernel.org 12879 + S: Supported 12880 + F: drivers/gpio/gpio-novalake-events.c 12873 12881 12874 12882 INTEL GVT-g DRIVERS (Intel GPU Virtualization) 12875 12883 R: Zhenyu Wang <zhenyuw.linux@gmail.com>
-1
arch/arc/plat-axs10x/Kconfig
··· 7 7 bool "Synopsys ARC AXS10x Software Development Platforms" 8 8 select DW_APB_ICTL 9 9 select GPIO_DWAPB 10 - select OF_GPIO 11 10 select HAVE_PCI 12 11 select GENERIC_IRQ_CHIP 13 12 select GPIOLIB
+27 -5
arch/arm/mach-omap1/board-ams-delta.c
··· 556 556 &ams_delta_nand_gpio_table, 557 557 }; 558 558 559 - static struct gpiod_hog ams_delta_gpio_hogs[] = { 560 - GPIO_HOG(LATCH2_LABEL, LATCH2_PIN_KEYBRD_DATAOUT, "keybrd_dataout", 561 - GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW), 562 - {}, 559 + static const struct software_node latch2_gpio_swnode = { 560 + .name = LATCH2_LABEL, 561 + }; 562 + 563 + static const u32 latch2_hog_gpios[] = { LATCH2_PIN_KEYBRD_DATAOUT, 0 }; 564 + 565 + static const struct property_entry latch2_gpio_hog_props[] = { 566 + PROPERTY_ENTRY_BOOL("gpio-hog"), 567 + PROPERTY_ENTRY_U32_ARRAY("gpios", latch2_hog_gpios), 568 + PROPERTY_ENTRY_STRING("line-name", "keybrd_dataout"), 569 + PROPERTY_ENTRY_BOOL("output-low"), 570 + { } 571 + }; 572 + 573 + static const struct software_node latch2_gpio_hog_swnode = { 574 + .parent = &latch2_gpio_swnode, 575 + .name = "latch2-hog", 576 + .properties = latch2_gpio_hog_props, 577 + }; 578 + 579 + static const struct software_node *const latch2_gpio_swnodes[] = { 580 + &latch2_gpio_swnode, 581 + &latch2_gpio_hog_swnode, 582 + NULL 563 583 }; 564 584 565 585 static struct plat_serial8250_port ams_delta_modem_ports[]; ··· 704 684 705 685 omap_gpio_deps_init(); 706 686 ams_delta_latch2_init(); 707 - gpiod_add_hogs(ams_delta_gpio_hogs); 708 687 709 688 omap_serial_init(); 710 689 omap_register_i2c_bus(1, 100, NULL, 0); ··· 712 693 platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices)); 713 694 714 695 platform_device_register_full(&latch1_gpio_devinfo); 696 + 697 + software_node_register_node_group(latch2_gpio_swnodes); 698 + latch2_gpio_devinfo.fwnode = software_node_fwnode(&latch2_gpio_swnode); 715 699 platform_device_register_full(&latch2_gpio_devinfo); 716 700 717 701 /*
-1
arch/powerpc/platforms/85xx/Kconfig
··· 217 217 config SGY_CTS1000 218 218 tristate "Servergy CTS-1000 support" 219 219 select GPIOLIB 220 - select OF_GPIO 221 220 depends on CORENET_GENERIC 222 221 help 223 222 Enable this to support functionality in Servergy's CTS-1000 systems.
+2
drivers/firmware/arm_scmi/pinctrl.c
··· 578 578 tx->flags = cpu_to_le32(type); 579 579 580 580 ret = ph->xops->do_xfer(ph, t); 581 + if (ret == -EOPNOTSUPP) 582 + ret = 0; 581 583 ph->xops->xfer_put(ph, t); 582 584 583 585 return ret;
+63 -45
drivers/gpio/Kconfig
··· 95 95 96 96 config GPIO_CDEV_V1 97 97 bool "Support GPIO ABI Version 1" 98 - default y 99 98 depends on GPIO_CDEV 100 99 help 101 100 Say Y here to support version 1 of the GPIO CDEV ABI. 102 101 103 102 This ABI version is deprecated. 104 103 Please use the latest ABI for new developments. 105 - 106 - If unsure, say Y. 107 104 108 105 config GPIO_GENERIC 109 106 depends on HAS_IOMEM # Only for IOMEM drivers ··· 142 145 143 146 config GPIO_74XX_MMIO 144 147 tristate "GPIO driver for 74xx-ICs with MMIO access" 145 - depends on OF_GPIO 148 + depends on OF 146 149 select GPIO_GENERIC 147 150 help 148 151 Say yes here to support GPIO functionality for 74xx-compatible ICs ··· 172 175 173 176 config GPIO_ASPEED 174 177 tristate "Aspeed GPIO support" 175 - depends on (ARCH_ASPEED || COMPILE_TEST) && OF_GPIO 178 + depends on ARCH_ASPEED || COMPILE_TEST 176 179 select GPIOLIB_IRQCHIP 177 180 help 178 181 Say Y here to support Aspeed AST2400 and AST2500 GPIO controllers. 179 182 180 183 config GPIO_ASPEED_SGPIO 181 184 bool "Aspeed SGPIO support" 182 - depends on (ARCH_ASPEED || COMPILE_TEST) && OF_GPIO 185 + depends on ARCH_ASPEED || COMPILE_TEST 183 186 select GPIO_GENERIC 184 187 select GPIOLIB_IRQCHIP 185 188 help ··· 198 201 config GPIO_RASPBERRYPI_EXP 199 202 tristate "Raspberry Pi 3 GPIO Expander" 200 203 default RASPBERRYPI_FIRMWARE 201 - depends on OF_GPIO 202 204 # Make sure not 'y' when RASPBERRYPI_FIRMWARE is 'm'. This can only 203 205 # happen when COMPILE_TEST=y, hence the added !RASPBERRYPI_FIRMWARE. 204 206 depends on (ARCH_BCM2835 && RASPBERRYPI_FIRMWARE) || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE) ··· 214 218 215 219 config GPIO_BCM_XGS_IPROC 216 220 tristate "BRCM XGS iProc GPIO support" 217 - depends on OF_GPIO && (ARCH_BCM_IPROC || COMPILE_TEST) 221 + depends on ARCH_BCM_IPROC || COMPILE_TEST 218 222 select GPIO_GENERIC 219 223 select GPIOLIB_IRQCHIP 220 224 default ARCH_BCM_IPROC ··· 225 229 tristate "Blaize BLZP1600 GPIO support" 226 230 default y if ARCH_BLAIZE 227 231 depends on ARCH_BLAIZE || COMPILE_TEST 228 - depends on OF_GPIO 229 232 select GPIO_GENERIC 230 233 select GPIOLIB_IRQCHIP 231 234 help ··· 235 240 config GPIO_BRCMSTB 236 241 tristate "BRCMSTB GPIO support" 237 242 default y if (ARCH_BRCMSTB || BMIPS_GENERIC) 238 - depends on OF_GPIO && (ARCH_BRCMSTB || ARCH_BCM2835 || BMIPS_GENERIC || COMPILE_TEST) 243 + depends on ARCH_BRCMSTB || ARCH_BCM2835 || BMIPS_GENERIC || COMPILE_TEST 244 + depends on OF 239 245 select GPIO_GENERIC 240 246 select IRQ_DOMAIN 241 247 help 242 248 Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs. 243 249 250 + config GPIO_BY_PINCTRL 251 + tristate "GPIO support based on a pure pin control backend" 252 + depends on GPIOLIB 253 + help 254 + Support for generic GPIO handling based on top of pin control. 255 + Traditionally, firmware creates a GPIO interface or a pin 256 + controller interface and we have a driver to support it. But 257 + in SCMI, the pin control interface is generic and we can 258 + create a simple GPIO device based on the pin control interface 259 + without doing anything custom. 260 + 261 + This driver is used to access GPIOs over the ARM SCMI protocol. 262 + 244 263 config GPIO_CADENCE 245 264 tristate "Cadence GPIO support" 246 - depends on OF_GPIO 265 + depends on OF 247 266 select GPIO_GENERIC 248 267 select GPIOLIB_IRQCHIP 249 268 help ··· 289 280 config GPIO_EIC_SPRD 290 281 tristate "Spreadtrum EIC support" 291 282 depends on ARCH_SPRD || COMPILE_TEST 292 - depends on OF_GPIO 293 283 select GPIOLIB_IRQCHIP 294 284 help 295 285 Say yes here to support Spreadtrum EIC device. 296 286 297 287 config GPIO_EM 298 288 tristate "Emma Mobile GPIO" 299 - depends on (ARCH_EMEV2 || COMPILE_TEST) && OF_GPIO 289 + depends on ARCH_EMEV2 || COMPILE_TEST 300 290 help 301 291 Say yes here to support GPIO on Renesas Emma Mobile SoCs. 302 292 ··· 337 329 338 330 config GPIO_FTGPIO010 339 331 bool "Faraday FTGPIO010 GPIO" 340 - depends on OF_GPIO 332 + depends on OF 341 333 select GPIO_GENERIC 342 334 select GPIOLIB_IRQCHIP 343 335 default (ARCH_GEMINI || ARCH_MOXART) ··· 391 383 392 384 config GPIO_HLWD 393 385 tristate "Nintendo Wii (Hollywood) GPIO" 394 - depends on OF_GPIO 386 + depends on OF 395 387 select GPIO_GENERIC 396 388 select GPIOLIB_IRQCHIP 397 389 help ··· 442 434 config GPIO_LOONGSON_64BIT 443 435 tristate "Loongson 64 bit GPIO support" 444 436 depends on LOONGARCH || COMPILE_TEST 445 - depends on OF_GPIO 446 437 select GPIO_GENERIC 447 438 select GPIOLIB_IRQCHIP 448 439 help ··· 454 447 config GPIO_LPC18XX 455 448 tristate "NXP LPC18XX/43XX GPIO support" 456 449 default y if ARCH_LPC18XX 457 - depends on OF_GPIO && (ARCH_LPC18XX || COMPILE_TEST) 450 + depends on ARCH_LPC18XX || COMPILE_TEST 458 451 select IRQ_DOMAIN_HIERARCHY 459 452 select GPIOLIB_IRQCHIP 460 453 help ··· 463 456 464 457 config GPIO_LPC32XX 465 458 tristate "NXP LPC32XX GPIO support" 466 - depends on OF_GPIO && (ARCH_LPC32XX || COMPILE_TEST) 459 + depends on ARCH_LPC32XX || COMPILE_TEST 460 + depends on OF 467 461 help 468 462 Select this option to enable GPIO driver for 469 463 NXP LPC32XX devices. ··· 507 499 config GPIO_MT7621 508 500 bool "Mediatek MT7621 GPIO Support" 509 501 depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST 510 - depends on OF_GPIO 502 + depends on OF 511 503 select GPIO_GENERIC 512 504 select GPIOLIB_IRQCHIP 513 505 help ··· 600 592 config GPIO_RDA 601 593 bool "RDA Micro GPIO controller support" 602 594 depends on ARCH_RDA || COMPILE_TEST 603 - depends on OF_GPIO 604 595 select GPIO_GENERIC 605 596 select GPIOLIB_IRQCHIP 606 597 help ··· 648 641 649 642 config GPIO_SAMA5D2_PIOBU 650 643 tristate "SAMA5D2 PIOBU GPIO support" 644 + depends on OF 651 645 depends on MFD_SYSCON 652 - depends on OF_GPIO 653 646 depends on ARCH_AT91 || COMPILE_TEST 654 647 select GPIO_SYSCON 655 648 help ··· 661 654 662 655 config GPIO_SIFIVE 663 656 tristate "SiFive GPIO support" 664 - depends on OF_GPIO 657 + depends on OF 665 658 select IRQ_DOMAIN_HIERARCHY 666 659 select GPIO_GENERIC 667 660 select GPIOLIB_IRQCHIP ··· 680 673 config GPIO_SNPS_CREG 681 674 bool "Synopsys GPIO via CREG (Control REGisters) driver" 682 675 depends on ARC || COMPILE_TEST 683 - depends on OF_GPIO 684 676 help 685 677 This driver supports GPIOs via CREG on various Synopsys SoCs. 686 678 This is a single-register MMIO GPIO driver for complex cases ··· 689 683 config GPIO_SPACEMIT_K1 690 684 tristate "SPACEMIT K1 GPIO support" 691 685 depends on ARCH_SPACEMIT || COMPILE_TEST 692 - depends on OF_GPIO 686 + depends on OF 693 687 select GPIO_GENERIC 694 688 select GPIOLIB_IRQCHIP 695 689 help ··· 705 699 config GPIO_SPRD 706 700 tristate "Spreadtrum GPIO support" 707 701 depends on ARCH_SPRD || COMPILE_TEST 708 - depends on OF_GPIO 709 702 select GPIOLIB_IRQCHIP 710 703 help 711 704 Say yes here to support Spreadtrum GPIO device. ··· 712 707 config GPIO_STP_XWAY 713 708 bool "XWAY STP GPIOs" 714 709 depends on SOC_XWAY || COMPILE_TEST 715 - depends on OF_GPIO 716 710 help 717 711 This enables support for the Serial To Parallel (STP) unit found on 718 712 XWAY SoC. The STP allows the SoC to drive a shift registers cascade, ··· 746 742 tristate "NVIDIA Tegra GPIO support" 747 743 default ARCH_TEGRA 748 744 depends on ARCH_TEGRA || COMPILE_TEST 749 - depends on OF_GPIO 750 745 select GPIOLIB_IRQCHIP 751 746 select IRQ_DOMAIN_HIERARCHY 752 747 help ··· 755 752 tristate "NVIDIA Tegra186 GPIO support" 756 753 default ARCH_TEGRA_186_SOC || ARCH_TEGRA_194_SOC || ARCH_TEGRA_234_SOC 757 754 depends on ARCH_TEGRA_186_SOC || ARCH_TEGRA_194_SOC || ARCH_TEGRA_234_SOC || COMPILE_TEST 758 - depends on OF_GPIO 755 + depends on OF 759 756 select GPIOLIB_IRQCHIP 760 757 select IRQ_DOMAIN_HIERARCHY 761 758 help ··· 763 760 764 761 config GPIO_TS4800 765 762 tristate "TS-4800 DIO blocks and compatibles" 766 - depends on OF_GPIO 767 763 depends on SOC_IMX51 || COMPILE_TEST 768 764 select GPIO_GENERIC 769 765 help ··· 782 780 config GPIO_UNIPHIER 783 781 tristate "UniPhier GPIO support" 784 782 depends on ARCH_UNIPHIER || COMPILE_TEST 785 - depends on OF_GPIO 786 783 select IRQ_DOMAIN_HIERARCHY 787 784 help 788 785 Say yes here to support UniPhier GPIOs. ··· 798 797 config GPIO_VISCONTI 799 798 tristate "Toshiba Visconti GPIO support" 800 799 depends on ARCH_VISCONTI || COMPILE_TEST 801 - depends on OF_GPIO 802 800 select GPIOLIB_IRQCHIP 803 801 select GPIO_GENERIC 804 802 select IRQ_DOMAIN_HIERARCHY ··· 806 806 807 807 config GPIO_WCD934X 808 808 tristate "Qualcomm Technologies Inc WCD9340/WCD9341 GPIO controller driver" 809 - depends on MFD_WCD934X && OF_GPIO 809 + depends on MFD_WCD934X 810 810 help 811 811 This driver is to support GPIO block found on the Qualcomm Technologies 812 812 Inc WCD9340/WCD9341 Audio Codec. 813 813 814 814 config GPIO_XGENE 815 815 bool "APM X-Gene GPIO controller support" 816 - depends on ARM64 && OF_GPIO 816 + depends on ARM64 817 817 help 818 818 This driver is to support the GPIO block within the APM X-Gene SoC 819 819 platform's generic flash controller. The GPIO pins are muxed with ··· 1057 1057 The Intel Quark X1000 SoC has 2 GPIOs powered by the core 1058 1058 power well and 6 from the suspend power well. 1059 1059 1060 + config GPIO_NOVALAKE 1061 + tristate "Intel Nova Lake GPIO-signaled ACPI events support" 1062 + depends on (X86 || COMPILE_TEST) && ACPI 1063 + select GPIOLIB_IRQCHIP 1064 + help 1065 + Select this to enable GPIO-signaled ACPI events support on platforms 1066 + with the following SoCs: 1067 + 1068 + - Intel Nova Lake 1069 + 1070 + This driver adds support for new mode of handling platform events, 1071 + through the use of GPIO-signaled ACPI events. Main purpose is to 1072 + handle platform IRQs that originate in PCH components, for example 1073 + interrupt triggered by Power Management Event (PME). 1074 + 1075 + This driver, at this time, is not required to handle platform events. 1076 + Listed platform(s) will stay in legacy mode, handling ACPI events as 1077 + in previous generations. However, future platforms will eventually 1078 + switch to new handling mode, requiring this driver to run events 1079 + properly. 1080 + 1081 + Driver supports up to 128 GPIO pins per GPE block. 1082 + 1083 + To compile this driver as a module, choose M here: the module will 1084 + be called gpio-novalake-events. 1085 + 1060 1086 config GPIO_SCH311X 1061 1087 tristate "SMSC SCH311x SuperI/O GPIO" 1062 1088 help ··· 1137 1111 1138 1112 config GPIO_ADNP 1139 1113 tristate "Avionic Design N-bit GPIO expander" 1140 - depends on OF_GPIO 1114 + depends on OF 1141 1115 select GPIOLIB_IRQCHIP 1142 1116 help 1143 1117 This option enables support for N GPIOs found on Avionic Design ··· 1170 1144 1171 1145 config GPIO_GW_PLD 1172 1146 tristate "Gateworks PLD GPIO Expander" 1173 - depends on OF_GPIO 1147 + depends on OF 1174 1148 help 1175 1149 Say yes here to provide access to the Gateworks I2C PLD GPIO 1176 1150 Expander. This is used at least on the Cambria GW2358-4. ··· 1466 1440 config GPIO_KEMPLD 1467 1441 tristate "Kontron ETX / COMexpress GPIO" 1468 1442 depends on MFD_KEMPLD 1443 + select GPIOLIB_IRQCHIP 1469 1444 help 1470 1445 This enables support for the PLD GPIO interface on some Kontron ETX 1471 1446 and COMexpress (ETXexpress) modules. ··· 1594 1567 config GPIO_PMIC_EIC_SPRD 1595 1568 tristate "Spreadtrum PMIC EIC support" 1596 1569 depends on MFD_SC27XX_PMIC || COMPILE_TEST 1597 - depends on OF_GPIO 1598 1570 select GPIOLIB_IRQCHIP 1599 1571 help 1600 1572 Say yes here to support Spreadtrum PMIC EIC device. ··· 1632 1606 config GPIO_STMPE 1633 1607 tristate "STMPE GPIOs" 1634 1608 depends on MFD_STMPE 1635 - depends on OF_GPIO 1636 1609 select GPIOLIB_IRQCHIP 1637 1610 help 1638 1611 This enables support for the GPIOs found on the STMPE I/O ··· 1640 1615 config GPIO_TC3589X 1641 1616 bool "TC3589X GPIOs" 1642 1617 depends on MFD_TC3589X 1643 - depends on OF_GPIO 1644 1618 select GPIOLIB_IRQCHIP 1645 1619 help 1646 1620 This enables support for the GPIOs found on the TC3589X ··· 2010 1986 config GPIO_AGGREGATOR 2011 1987 tristate "GPIO Aggregator" 2012 1988 select CONFIGFS_FS 2013 - select DEV_SYNC_PROBE 2014 1989 help 2015 1990 Say yes here to enable the GPIO Aggregator, which provides a way to 2016 1991 aggregate existing GPIO lines into a new virtual GPIO chip. ··· 2028 2005 2029 2006 config GPIO_LINE_MUX 2030 2007 tristate "GPIO line mux driver" 2031 - depends on OF_GPIO 2008 + depends on OF 2032 2009 select MULTIPLEXER 2033 2010 help 2034 2011 Say Y here to support the GPIO line mux, which can provide virtual ··· 2061 2038 tristate "GPIO Simulator Module" 2062 2039 select IRQ_SIM 2063 2040 select CONFIGFS_FS 2064 - select DEV_SYNC_PROBE 2065 2041 help 2066 2042 This enables the GPIO simulator - a configfs-based GPIO testing 2067 2043 driver. ··· 2098 2076 select DEBUG_FS 2099 2077 select CONFIGFS_FS 2100 2078 select IRQ_WORK 2101 - select DEV_SYNC_PROBE 2102 2079 help 2103 2080 Say Y here to enable the configurable, configfs-based virtual GPIO 2104 2081 consumer testing driver. ··· 2108 2087 endmenu 2109 2088 2110 2089 endif 2111 - 2112 - config DEV_SYNC_PROBE 2113 - tristate
+2 -3
drivers/gpio/Makefile
··· 21 21 # directly supported by gpio-generic 22 22 gpio-generic-$(CONFIG_GPIO_GENERIC) += gpio-mmio.o 23 23 24 - # Utilities for drivers that need synchronous fake device creation 25 - obj-$(CONFIG_DEV_SYNC_PROBE) += dev-sync-probe.o 26 - 27 24 obj-$(CONFIG_GPIO_104_DIO_48E) += gpio-104-dio-48e.o 28 25 obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o 29 26 obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o ··· 48 51 obj-$(CONFIG_GPIO_BLZP1600) += gpio-blzp1600.o 49 52 obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o 50 53 obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o 54 + obj-$(CONFIG_GPIO_BY_PINCTRL) += gpio-by-pinctrl.o 51 55 obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o 52 56 obj-$(CONFIG_GPIO_CGBC) += gpio-cgbc.o 53 57 obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o ··· 132 134 obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o 133 135 obj-$(CONFIG_GPIO_NCT6694) += gpio-nct6694.o 134 136 obj-$(CONFIG_GPIO_NOMADIK) += gpio-nomadik.o 137 + obj-$(CONFIG_GPIO_NOVALAKE) += gpio-novalake-events.o 135 138 obj-$(CONFIG_GPIO_NPCM_SGPIO) += gpio-npcm-sgpio.o 136 139 obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o 137 140 obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o
-28
drivers/gpio/TODO
··· 58 58 59 59 ------------------------------------------------------------------------------- 60 60 61 - Get rid of <linux/of_gpio.h> 62 - 63 - This header and helpers appeared at one point when there was no proper 64 - driver infrastructure for doing simpler MMIO GPIO devices and there was 65 - no core support for parsing device tree GPIOs from the core library with 66 - the [devm_]gpiod_get() calls we have today that will implicitly go into 67 - the device tree back-end. It is legacy and should not be used in new code. 68 - 69 - Work items: 70 - 71 - - Change all consumer drivers that #include <linux/of_gpio.h> to 72 - #include <linux/gpio/consumer.h> and stop doing custom parsing of the 73 - GPIO lines from the device tree. This can be tricky and often involves 74 - changing board files, etc. 75 - 76 - - Pull semantics for legacy device tree (OF) GPIO lookups into 77 - gpiolib-of.c: in some cases subsystems are doing custom flags and 78 - lookups for polarity inversion, open drain and what not. As we now 79 - handle this with generic OF bindings, pull all legacy handling into 80 - gpiolib so the library API becomes narrow and deep and handle all 81 - legacy bindings internally. (See e.g. commits 6953c57ab172, 82 - 6a537d48461d etc) 83 - 84 - - Delete <linux/of_gpio.h> when all the above is complete and everything 85 - uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 86 - 87 - ------------------------------------------------------------------------------- 88 - 89 61 Collect drivers 90 62 91 63 Collect GPIO drivers from arch/* and other places that should be placed
-97
drivers/gpio/dev-sync-probe.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Common code for drivers creating fake platform devices. 4 - * 5 - * Provides synchronous device creation: waits for probe completion and 6 - * returns the probe success or error status to the device creator. 7 - * 8 - * Copyright (C) 2021 Bartosz Golaszewski <brgl@bgdev.pl> 9 - * Copyright (C) 2025 Koichiro Den <koichiro.den@canonical.com> 10 - */ 11 - 12 - #include <linux/device.h> 13 - #include <linux/slab.h> 14 - 15 - #include "dev-sync-probe.h" 16 - 17 - static int dev_sync_probe_notifier_call(struct notifier_block *nb, 18 - unsigned long action, void *data) 19 - { 20 - struct dev_sync_probe_data *pdata; 21 - struct device *dev = data; 22 - 23 - pdata = container_of(nb, struct dev_sync_probe_data, bus_notifier); 24 - if (!device_match_name(dev, pdata->name)) 25 - return NOTIFY_DONE; 26 - 27 - switch (action) { 28 - case BUS_NOTIFY_BOUND_DRIVER: 29 - pdata->driver_bound = true; 30 - break; 31 - case BUS_NOTIFY_DRIVER_NOT_BOUND: 32 - pdata->driver_bound = false; 33 - break; 34 - default: 35 - return NOTIFY_DONE; 36 - } 37 - 38 - complete(&pdata->probe_completion); 39 - return NOTIFY_OK; 40 - } 41 - 42 - void dev_sync_probe_init(struct dev_sync_probe_data *data) 43 - { 44 - memset(data, 0, sizeof(*data)); 45 - init_completion(&data->probe_completion); 46 - data->bus_notifier.notifier_call = dev_sync_probe_notifier_call; 47 - } 48 - EXPORT_SYMBOL_GPL(dev_sync_probe_init); 49 - 50 - int dev_sync_probe_register(struct dev_sync_probe_data *data, 51 - struct platform_device_info *pdevinfo) 52 - { 53 - struct platform_device *pdev; 54 - char *name; 55 - 56 - name = kasprintf(GFP_KERNEL, "%s.%d", pdevinfo->name, pdevinfo->id); 57 - if (!name) 58 - return -ENOMEM; 59 - 60 - data->driver_bound = false; 61 - data->name = name; 62 - reinit_completion(&data->probe_completion); 63 - bus_register_notifier(&platform_bus_type, &data->bus_notifier); 64 - 65 - pdev = platform_device_register_full(pdevinfo); 66 - if (IS_ERR(pdev)) { 67 - bus_unregister_notifier(&platform_bus_type, &data->bus_notifier); 68 - kfree(data->name); 69 - return PTR_ERR(pdev); 70 - } 71 - 72 - wait_for_completion(&data->probe_completion); 73 - bus_unregister_notifier(&platform_bus_type, &data->bus_notifier); 74 - 75 - if (!data->driver_bound) { 76 - platform_device_unregister(pdev); 77 - kfree(data->name); 78 - return -ENXIO; 79 - } 80 - 81 - data->pdev = pdev; 82 - return 0; 83 - } 84 - EXPORT_SYMBOL_GPL(dev_sync_probe_register); 85 - 86 - void dev_sync_probe_unregister(struct dev_sync_probe_data *data) 87 - { 88 - platform_device_unregister(data->pdev); 89 - kfree(data->name); 90 - data->pdev = NULL; 91 - } 92 - EXPORT_SYMBOL_GPL(dev_sync_probe_unregister); 93 - 94 - MODULE_AUTHOR("Bartosz Golaszewski <brgl@bgdev.pl>"); 95 - MODULE_AUTHOR("Koichiro Den <koichiro.den@canonical.com>"); 96 - MODULE_DESCRIPTION("Utilities for synchronous fake device creation"); 97 - MODULE_LICENSE("GPL");
-25
drivers/gpio/dev-sync-probe.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - 3 - #ifndef DEV_SYNC_PROBE_H 4 - #define DEV_SYNC_PROBE_H 5 - 6 - #include <linux/completion.h> 7 - #include <linux/notifier.h> 8 - #include <linux/platform_device.h> 9 - 10 - struct dev_sync_probe_data { 11 - struct platform_device *pdev; 12 - const char *name; 13 - 14 - /* Synchronize with probe */ 15 - struct notifier_block bus_notifier; 16 - struct completion probe_completion; 17 - bool driver_bound; 18 - }; 19 - 20 - void dev_sync_probe_init(struct dev_sync_probe_data *data); 21 - int dev_sync_probe_register(struct dev_sync_probe_data *data, 22 - struct platform_device_info *pdevinfo); 23 - void dev_sync_probe_unregister(struct dev_sync_probe_data *data); 24 - 25 - #endif /* DEV_SYNC_PROBE_H */
+21 -17
drivers/gpio/gpio-aggregator.c
··· 32 32 #include <linux/gpio/forwarder.h> 33 33 #include <linux/gpio/machine.h> 34 34 35 - #include "dev-sync-probe.h" 36 - 37 35 #define AGGREGATOR_MAX_GPIOS 512 38 36 #define AGGREGATOR_LEGACY_PREFIX "_sysfs" 39 37 ··· 40 42 */ 41 43 42 44 struct gpio_aggregator { 43 - struct dev_sync_probe_data probe_data; 45 + struct platform_device *pdev; 44 46 struct config_group group; 45 47 struct gpiod_lookup_table *lookups; 46 48 struct mutex lock; ··· 133 135 { 134 136 lockdep_assert_held(&aggr->lock); 135 137 136 - return aggr->probe_data.pdev && platform_get_drvdata(aggr->probe_data.pdev); 138 + return aggr->pdev && platform_get_drvdata(aggr->pdev); 137 139 } 138 140 139 141 /* Only aggregators created via legacy sysfs can be "activating". */ ··· 141 143 { 142 144 lockdep_assert_held(&aggr->lock); 143 145 144 - return aggr->probe_data.pdev && !platform_get_drvdata(aggr->probe_data.pdev); 146 + return aggr->pdev && !platform_get_drvdata(aggr->pdev); 145 147 } 146 148 147 149 static size_t gpio_aggregator_count_lines(struct gpio_aggregator *aggr) ··· 907 909 { 908 910 struct platform_device_info pdevinfo; 909 911 struct gpio_aggregator_line *line; 912 + struct platform_device *pdev; 910 913 struct fwnode_handle *swnode; 911 914 unsigned int n = 0; 912 915 int ret = 0; ··· 961 962 962 963 gpiod_add_lookup_table(aggr->lookups); 963 964 964 - ret = dev_sync_probe_register(&aggr->probe_data, &pdevinfo); 965 - if (ret) 965 + pdev = platform_device_register_full(&pdevinfo); 966 + if (IS_ERR(pdev)) { 967 + ret = PTR_ERR(pdev); 966 968 goto err_remove_lookup_table; 969 + } 967 970 971 + wait_for_device_probe(); 972 + if (!device_is_bound(&pdev->dev)) { 973 + ret = -ENXIO; 974 + goto err_unregister_pdev; 975 + } 976 + 977 + aggr->pdev = pdev; 968 978 return 0; 969 979 980 + err_unregister_pdev: 981 + platform_device_unregister(pdev); 970 982 err_remove_lookup_table: 971 983 kfree(aggr->lookups->dev_id); 972 984 gpiod_remove_lookup_table(aggr->lookups); ··· 991 981 992 982 static void gpio_aggregator_deactivate(struct gpio_aggregator *aggr) 993 983 { 994 - dev_sync_probe_unregister(&aggr->probe_data); 984 + platform_device_unregister(aggr->pdev); 985 + aggr->pdev = NULL; 995 986 gpiod_remove_lookup_table(aggr->lookups); 996 987 kfree(aggr->lookups->dev_id); 997 988 kfree(aggr->lookups); ··· 1156 1145 1157 1146 guard(mutex)(&aggr->lock); 1158 1147 1159 - pdev = aggr->probe_data.pdev; 1148 + pdev = aggr->pdev; 1160 1149 if (pdev) 1161 1150 return sysfs_emit(page, "%s\n", dev_name(&pdev->dev)); 1162 1151 ··· 1333 1322 return ERR_PTR(ret); 1334 1323 1335 1324 config_group_init_type_name(&aggr->group, name, &gpio_aggregator_device_type); 1336 - dev_sync_probe_init(&aggr->probe_data); 1337 1325 1338 1326 return &aggr->group; 1339 1327 } ··· 1481 1471 scnprintf(name, sizeof(name), "%s.%d", AGGREGATOR_LEGACY_PREFIX, aggr->id); 1482 1472 config_group_init_type_name(&aggr->group, name, &gpio_aggregator_device_type); 1483 1473 1484 - /* 1485 - * Since the device created by sysfs might be toggled via configfs 1486 - * 'live' attribute later, this initialization is needed. 1487 - */ 1488 - dev_sync_probe_init(&aggr->probe_data); 1489 - 1490 1474 /* Expose to configfs */ 1491 1475 res = configfs_register_group(&gpio_aggregator_subsys.su_group, 1492 1476 &aggr->group); ··· 1499 1495 goto remove_table; 1500 1496 } 1501 1497 1502 - aggr->probe_data.pdev = pdev; 1498 + aggr->pdev = pdev; 1503 1499 module_put(THIS_MODULE); 1504 1500 return count; 1505 1501
+1 -1
drivers/gpio/gpio-aspeed.c
··· 655 655 656 656 while (!is_bank_props_sentinel(props)) { 657 657 unsigned int offset; 658 - const unsigned long int input = props->input; 658 + const unsigned long input = props->input; 659 659 660 660 /* Pretty crummy approach, but similar to GPIO core */ 661 661 for_each_clear_bit(offset, &input, 32) {
+16 -21
drivers/gpio/gpio-bcm-kona.c
··· 58 58 #define LOCK_CODE 0xffffffff 59 59 #define UNLOCK_CODE 0x00000000 60 60 61 - struct bcm_kona_gpio { 62 - void __iomem *reg_base; 63 - int num_bank; 64 - raw_spinlock_t lock; 65 - struct gpio_chip gpio_chip; 66 - struct irq_domain *irq_domain; 67 - struct bcm_kona_gpio_bank *banks; 68 - }; 69 - 70 61 struct bcm_kona_gpio_bank { 71 62 int id; 72 63 int irq; ··· 79 88 u8 gpio_unlock_count[GPIO_PER_BANK]; 80 89 /* Used in the interrupt handler */ 81 90 struct bcm_kona_gpio *kona_gpio; 91 + }; 92 + 93 + struct bcm_kona_gpio { 94 + void __iomem *reg_base; 95 + int num_bank; 96 + raw_spinlock_t lock; 97 + struct gpio_chip gpio_chip; 98 + struct irq_domain *irq_domain; 99 + struct bcm_kona_gpio_bank banks[] __counted_by(num_bank); 82 100 }; 83 101 84 102 static inline void bcm_kona_gpio_write_lock_regs(void __iomem *reg_base, ··· 584 584 int ret; 585 585 int i; 586 586 587 - kona_gpio = devm_kzalloc(dev, sizeof(*kona_gpio), GFP_KERNEL); 588 - if (!kona_gpio) 589 - return -ENOMEM; 590 - 591 - kona_gpio->gpio_chip = template_chip; 592 - chip = &kona_gpio->gpio_chip; 593 587 ret = platform_irq_count(pdev); 594 588 if (!ret) { 595 589 dev_err(dev, "Couldn't determine # GPIO banks\n"); ··· 591 597 } else if (ret < 0) { 592 598 return dev_err_probe(dev, ret, "Couldn't determine GPIO banks\n"); 593 599 } 600 + 601 + kona_gpio = devm_kzalloc(dev, struct_size(kona_gpio, banks, ret), GFP_KERNEL); 602 + if (!kona_gpio) 603 + return -ENOMEM; 604 + 594 605 kona_gpio->num_bank = ret; 595 606 596 607 if (kona_gpio->num_bank > GPIO_MAX_BANK_NUM) { ··· 603 604 GPIO_MAX_BANK_NUM); 604 605 return -ENXIO; 605 606 } 606 - kona_gpio->banks = devm_kcalloc(dev, 607 - kona_gpio->num_bank, 608 - sizeof(*kona_gpio->banks), 609 - GFP_KERNEL); 610 - if (!kona_gpio->banks) 611 - return -ENOMEM; 612 607 608 + kona_gpio->gpio_chip = template_chip; 609 + chip = &kona_gpio->gpio_chip; 613 610 chip->parent = dev; 614 611 chip->ngpio = kona_gpio->num_bank * GPIO_PER_BANK; 615 612
+1 -1
drivers/gpio/gpio-bd9571mwv.c
··· 69 69 if (ret < 0) 70 70 return ret; 71 71 72 - return val & BIT(offset); 72 + return !!(val & BIT(offset)); 73 73 } 74 74 75 75 static int bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
+87 -38
drivers/gpio/gpio-brcmstb.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - // Copyright (C) 2015-2017 Broadcom 2 + // Copyright (C) 2015-2017, 2026 Broadcom 3 3 4 4 #include <linux/bitops.h> 5 5 #include <linux/gpio/driver.h> ··· 54 54 int parent_irq; 55 55 int num_gpios; 56 56 int parent_wake_irq; 57 + bool suspended; 57 58 }; 58 59 59 60 #define MAX_GPIO_PER_BANK 32 ··· 96 95 return hwirq - bank->chip.gc.offset; 97 96 } 98 97 99 - static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, 100 - unsigned int hwirq, bool enable) 98 + static void __brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, 99 + irq_hw_number_t hwirq, bool enable) 101 100 { 102 101 struct brcmstb_gpio_priv *priv = bank->parent_priv; 103 102 u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(hwirq, bank)); 104 103 u32 imask; 105 - 106 - guard(gpio_generic_lock_irqsave)(&bank->chip); 107 104 108 105 imask = gpio_generic_read_reg(&bank->chip, 109 106 priv->reg_base + GIO_MASK(bank->id)); ··· 111 112 imask &= ~mask; 112 113 gpio_generic_write_reg(&bank->chip, 113 114 priv->reg_base + GIO_MASK(bank->id), imask); 115 + } 116 + 117 + static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, 118 + irq_hw_number_t hwirq, bool enable) 119 + { 120 + guard(gpio_generic_lock_irqsave)(&bank->chip); 121 + __brcmstb_gpio_set_imask(bank, hwirq, enable); 114 122 } 115 123 116 124 static int brcmstb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) ··· 138 132 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 139 133 struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 140 134 141 - brcmstb_gpio_set_imask(bank, d->hwirq, false); 135 + brcmstb_gpio_set_imask(bank, irqd_to_hwirq(d), false); 136 + } 137 + 138 + static void brcmstb_gpio_irq_mask_ack(struct irq_data *d) 139 + { 140 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 141 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 142 + struct brcmstb_gpio_priv *priv = bank->parent_priv; 143 + irq_hw_number_t hwirq = irqd_to_hwirq(d); 144 + u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(hwirq, bank)); 145 + 146 + guard(gpio_generic_lock_irqsave)(&bank->chip); 147 + __brcmstb_gpio_set_imask(bank, hwirq, false); 148 + gpio_generic_write_reg(&bank->chip, 149 + priv->reg_base + GIO_STAT(bank->id), mask); 142 150 } 143 151 144 152 static void brcmstb_gpio_irq_unmask(struct irq_data *d) ··· 160 140 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 161 141 struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 162 142 163 - brcmstb_gpio_set_imask(bank, d->hwirq, true); 143 + brcmstb_gpio_set_imask(bank, irqd_to_hwirq(d), true); 164 144 } 165 145 166 146 static void brcmstb_gpio_irq_ack(struct irq_data *d) ··· 168 148 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 169 149 struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 170 150 struct brcmstb_gpio_priv *priv = bank->parent_priv; 171 - u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(d->hwirq, bank)); 151 + u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(irqd_to_hwirq(d), bank)); 172 152 173 153 gpio_generic_write_reg(&bank->chip, 174 154 priv->reg_base + GIO_STAT(bank->id), mask); ··· 179 159 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 180 160 struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 181 161 struct brcmstb_gpio_priv *priv = bank->parent_priv; 182 - u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(d->hwirq, bank)); 162 + u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(irqd_to_hwirq(d), bank)); 183 163 u32 edge_insensitive, iedge_insensitive; 184 164 u32 edge_config, iedge_config; 185 165 u32 level, ilevel; ··· 241 221 { 242 222 int ret = 0; 243 223 224 + if (priv->parent_wake_irq == priv->parent_irq) 225 + return ret; 226 + 244 227 if (enable) 245 228 ret = enable_irq_wake(priv->parent_wake_irq); 246 229 else ··· 259 236 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 260 237 struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 261 238 struct brcmstb_gpio_priv *priv = bank->parent_priv; 262 - u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(d->hwirq, bank)); 239 + u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(irqd_to_hwirq(d), bank)); 263 240 264 241 /* 265 242 * Do not do anything specific for now, suspend/resume callbacks will ··· 293 270 294 271 while ((status = brcmstb_gpio_get_active_irqs(bank))) { 295 272 unsigned int offset; 273 + 274 + if (priv->suspended && bank->wake_active & status) { 275 + priv->suspended = false; 276 + pm_wakeup_event(&priv->pdev->dev, 0); 277 + } 296 278 297 279 for_each_set_bit(offset, &status, 32) { 298 280 if (offset >= bank->width) ··· 472 444 } 473 445 474 446 if (of_property_read_bool(np, "wakeup-source")) { 447 + /* 448 + * Set wakeup capability so we can process boot-time 449 + * "wakeups" (e.g., from S5 cold boot). 450 + */ 451 + device_set_wakeup_capable(dev, true); 452 + device_wakeup_enable(dev); 475 453 priv->parent_wake_irq = platform_get_irq(pdev, 1); 476 454 if (priv->parent_wake_irq < 0) { 477 - priv->parent_wake_irq = 0; 455 + priv->parent_wake_irq = priv->parent_irq; 478 456 dev_warn(dev, 479 457 "Couldn't get wake IRQ - GPIOs will not be able to wake from sleep"); 480 458 } else { 481 - /* 482 - * Set wakeup capability so we can process boot-time 483 - * "wakeups" (e.g., from S5 cold boot) 484 - */ 485 - device_set_wakeup_capable(dev, true); 486 - device_wakeup_enable(dev); 487 459 err = devm_request_irq(dev, priv->parent_wake_irq, 488 460 brcmstb_gpio_wake_irq_handler, 489 461 IRQF_SHARED, ··· 494 466 goto out_free_domain; 495 467 } 496 468 } 469 + priv->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; 497 470 } 498 471 499 472 priv->irq_chip.name = dev_name(dev); 500 473 priv->irq_chip.irq_disable = brcmstb_gpio_irq_mask; 501 474 priv->irq_chip.irq_mask = brcmstb_gpio_irq_mask; 475 + priv->irq_chip.irq_mask_ack = brcmstb_gpio_irq_mask_ack; 502 476 priv->irq_chip.irq_unmask = brcmstb_gpio_irq_unmask; 503 477 priv->irq_chip.irq_ack = brcmstb_gpio_irq_ack; 504 478 priv->irq_chip.irq_set_type = brcmstb_gpio_irq_set_type; 505 - 506 - if (priv->parent_wake_irq) 507 - priv->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; 508 479 509 480 irq_set_chained_handler_and_data(priv->parent_irq, 510 481 brcmstb_gpio_irq_handler, priv); ··· 527 500 priv->reg_base + GIO_BANK_OFF(bank->id, i)); 528 501 } 529 502 530 - static void brcmstb_gpio_quiesce(struct device *dev, bool save) 503 + static void brcmstb_gpio_quiesce(struct brcmstb_gpio_priv *priv, bool save) 531 504 { 532 - struct brcmstb_gpio_priv *priv = dev_get_drvdata(dev); 533 505 struct brcmstb_gpio_bank *bank; 534 506 u32 imask; 535 - 536 - /* disable non-wake interrupt */ 537 - if (priv->parent_irq >= 0) 538 - disable_irq(priv->parent_irq); 539 507 540 508 list_for_each_entry(bank, &priv->bank_list, node) { 541 509 if (save) ··· 549 527 550 528 static void brcmstb_gpio_shutdown(struct platform_device *pdev) 551 529 { 530 + struct brcmstb_gpio_priv *priv = dev_get_drvdata(&pdev->dev); 531 + 532 + if (priv->parent_irq > 0) 533 + disable_irq(priv->parent_irq); 534 + 552 535 /* Enable GPIO for S5 cold boot */ 553 - brcmstb_gpio_quiesce(&pdev->dev, false); 536 + brcmstb_gpio_quiesce(priv, false); 554 537 } 555 538 556 539 static void brcmstb_gpio_bank_restore(struct brcmstb_gpio_priv *priv, ··· 571 544 572 545 static int brcmstb_gpio_suspend(struct device *dev) 573 546 { 574 - brcmstb_gpio_quiesce(dev, true); 547 + struct brcmstb_gpio_priv *priv = dev_get_drvdata(dev); 548 + 549 + if (priv->parent_irq > 0) 550 + priv->suspended = true; 551 + 552 + return 0; 553 + } 554 + 555 + static int brcmstb_gpio_suspend_noirq(struct device *dev) 556 + { 557 + struct brcmstb_gpio_priv *priv = dev_get_drvdata(dev); 558 + 559 + /* Catch any wakeup sources occurring between suspend and noirq */ 560 + if (!priv->suspended) 561 + return -EBUSY; 562 + 563 + if (priv->parent_irq > 0) 564 + disable_irq(priv->parent_irq); 565 + 566 + brcmstb_gpio_quiesce(priv, true); 567 + 568 + if (priv->parent_wake_irq) 569 + enable_irq(priv->parent_irq); 570 + 575 571 return 0; 576 572 } 577 573 ··· 602 552 { 603 553 struct brcmstb_gpio_priv *priv = dev_get_drvdata(dev); 604 554 struct brcmstb_gpio_bank *bank; 605 - bool need_wakeup_event = false; 606 555 607 - list_for_each_entry(bank, &priv->bank_list, node) { 608 - need_wakeup_event |= !!__brcmstb_gpio_get_active_irqs(bank); 556 + if (priv->parent_wake_irq) 557 + disable_irq(priv->parent_irq); 558 + 559 + priv->suspended = false; 560 + 561 + list_for_each_entry(bank, &priv->bank_list, node) 609 562 brcmstb_gpio_bank_restore(priv, bank); 610 - } 611 563 612 - if (priv->parent_wake_irq && need_wakeup_event) 613 - pm_wakeup_event(dev, 0); 614 - 615 - /* enable non-wake interrupt */ 616 - if (priv->parent_irq >= 0) 564 + if (priv->parent_irq > 0) 617 565 enable_irq(priv->parent_irq); 618 566 619 567 return 0; 620 568 } 621 569 622 570 static const struct dev_pm_ops brcmstb_gpio_pm_ops = { 623 - .suspend_noirq = pm_sleep_ptr(brcmstb_gpio_suspend), 571 + .suspend = pm_sleep_ptr(brcmstb_gpio_suspend), 572 + .suspend_noirq = pm_sleep_ptr(brcmstb_gpio_suspend_noirq), 624 573 .resume_noirq = pm_sleep_ptr(brcmstb_gpio_resume), 625 574 }; 626 575
+101
drivers/gpio/gpio-by-pinctrl.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // 3 + // Copyright (C) 2026 Linaro Inc. 4 + // Author: AKASHI takahiro <takahiro.akashi@linaro.org> 5 + 6 + #include <linux/errno.h> 7 + #include <linux/gpio/driver.h> 8 + #include <linux/mod_devicetable.h> 9 + #include <linux/module.h> 10 + #include <linux/pinctrl/consumer.h> 11 + #include <linux/platform_device.h> 12 + #include <linux/types.h> 13 + 14 + #include "gpiolib.h" 15 + 16 + static int pin_control_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) 17 + { 18 + unsigned long config; 19 + int ret; 20 + 21 + config = PIN_CONFIG_OUTPUT_ENABLE; 22 + ret = pinctrl_gpio_get_config(gc, offset, &config); 23 + if (ret) 24 + return ret; 25 + if (config) 26 + return GPIO_LINE_DIRECTION_OUT; 27 + 28 + return GPIO_LINE_DIRECTION_IN; 29 + } 30 + 31 + static int pin_control_gpio_direction_output(struct gpio_chip *chip, 32 + unsigned int offset, int val) 33 + { 34 + return pinctrl_gpio_direction_output(chip, offset); 35 + } 36 + 37 + static int pin_control_gpio_get(struct gpio_chip *chip, unsigned int offset) 38 + { 39 + unsigned long config; 40 + int ret; 41 + 42 + config = PIN_CONFIG_LEVEL; 43 + ret = pinctrl_gpio_get_config(chip, offset, &config); 44 + if (ret) 45 + return ret; 46 + 47 + return !!config; 48 + } 49 + 50 + static int pin_control_gpio_set(struct gpio_chip *chip, unsigned int offset, 51 + int val) 52 + { 53 + unsigned long config; 54 + 55 + config = pinconf_to_config_packed(PIN_CONFIG_LEVEL, val); 56 + return pinctrl_gpio_set_config(chip, offset, config); 57 + } 58 + 59 + static int pin_control_gpio_probe(struct platform_device *pdev) 60 + { 61 + struct device *dev = &pdev->dev; 62 + struct gpio_chip *chip; 63 + 64 + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 65 + if (!chip) 66 + return -ENOMEM; 67 + 68 + chip->label = dev_name(dev); 69 + chip->parent = dev; 70 + chip->base = -1; 71 + 72 + chip->request = gpiochip_generic_request; 73 + chip->free = gpiochip_generic_free; 74 + chip->get_direction = pin_control_gpio_get_direction; 75 + chip->direction_input = pinctrl_gpio_direction_input; 76 + chip->direction_output = pin_control_gpio_direction_output; 77 + chip->get = pin_control_gpio_get; 78 + chip->set = pin_control_gpio_set; 79 + chip->set_config = gpiochip_generic_config; 80 + 81 + return devm_gpiochip_add_data(dev, chip, NULL); 82 + } 83 + 84 + static const struct of_device_id pin_control_gpio_match[] = { 85 + { .compatible = "scmi-pinctrl-gpio" }, 86 + { /* sentinel */ } 87 + }; 88 + MODULE_DEVICE_TABLE(of, pin_control_gpio_match); 89 + 90 + static struct platform_driver pin_control_gpio_driver = { 91 + .probe = pin_control_gpio_probe, 92 + .driver = { 93 + .name = "pin-control-gpio", 94 + .of_match_table = pin_control_gpio_match, 95 + }, 96 + }; 97 + module_platform_driver(pin_control_gpio_driver); 98 + 99 + MODULE_AUTHOR("AKASHI Takahiro <takahiro.akashi@linaro.org>"); 100 + MODULE_DESCRIPTION("Pinctrl based GPIO driver"); 101 + MODULE_LICENSE("GPL");
+2 -2
drivers/gpio/gpio-cgbc.c
··· 47 47 48 48 if (ret) 49 49 return ret; 50 - else 51 - return (int)(val & (u8)BIT(offset)); 50 + 51 + return !!(val & BIT(offset)); 52 52 } 53 53 54 54 static int __cgbc_gpio_set(struct gpio_chip *chip, unsigned int offset,
+21 -27
drivers/gpio/gpio-cs5535.c
··· 39 39 module_param_named(mask, mask, ulong, 0444); 40 40 MODULE_PARM_DESC(mask, "GPIO channel mask."); 41 41 42 - /* 43 - * FIXME: convert this singleton driver to use the state container 44 - * design pattern, see Documentation/driver-api/driver-model/design-patterns.rst 45 - */ 46 42 static struct cs5535_gpio_chip { 47 43 struct gpio_chip chip; 48 44 resource_size_t base; ··· 281 285 "GPIO28", NULL, NULL, NULL, 282 286 }; 283 287 284 - static struct cs5535_gpio_chip cs5535_gpio_chip = { 285 - .chip = { 286 - .owner = THIS_MODULE, 287 - .label = DRV_NAME, 288 - 289 - .base = 0, 290 - .ngpio = 32, 291 - .names = cs5535_gpio_names, 292 - .request = chip_gpio_request, 293 - 294 - .get = chip_gpio_get, 295 - .set = chip_gpio_set, 296 - 297 - .direction_input = chip_direction_input, 298 - .direction_output = chip_direction_output, 299 - }, 300 - }; 301 - 302 288 static int cs5535_gpio_probe(struct platform_device *pdev) 303 289 { 290 + struct cs5535_gpio_chip *priv; 291 + struct gpio_chip *gc; 304 292 struct resource *res; 305 293 int err = -EIO; 306 294 ulong mask_orig = mask; 295 + 296 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 297 + if (!priv) 298 + return -ENOMEM; 299 + 300 + gc = &priv->chip; 301 + gc->owner = THIS_MODULE; 302 + gc->label = DRV_NAME; 303 + gc->ngpio = 32; 304 + gc->names = cs5535_gpio_names; 305 + gc->request = chip_gpio_request; 306 + gc->get = chip_gpio_get; 307 + gc->set = chip_gpio_set; 308 + gc->direction_input = chip_direction_input; 309 + gc->direction_output = chip_direction_output; 307 310 308 311 /* There are two ways to get the GPIO base address; one is by 309 312 * fetching it from MSR_LBAR_GPIO, the other is by reading the ··· 324 329 } 325 330 326 331 /* set up the driver-specific struct */ 327 - cs5535_gpio_chip.base = res->start; 328 - cs5535_gpio_chip.pdev = pdev; 329 - spin_lock_init(&cs5535_gpio_chip.lock); 332 + priv->base = res->start; 333 + priv->pdev = pdev; 334 + spin_lock_init(&priv->lock); 330 335 331 336 dev_info(&pdev->dev, "reserved resource region %pR\n", res); 332 337 ··· 342 347 mask_orig, mask); 343 348 344 349 /* finally, register with the generic GPIO API */ 345 - return devm_gpiochip_add_data(&pdev->dev, &cs5535_gpio_chip.chip, 346 - &cs5535_gpio_chip); 350 + return devm_gpiochip_add_data(&pdev->dev, gc, priv); 347 351 } 348 352 349 353 static struct platform_driver cs5535_gpio_driver = {
+1 -1
drivers/gpio/gpio-da9055.c
··· 55 55 return ret; 56 56 } 57 57 58 - return ret & (1 << offset); 58 + return !!(ret & (1 << offset)); 59 59 60 60 } 61 61
+5 -14
drivers/gpio/gpio-dwapb.c
··· 75 75 }; 76 76 77 77 struct dwapb_platform_data { 78 - struct dwapb_port_property *properties; 79 78 unsigned int nports; 79 + struct dwapb_port_property properties[] __counted_by(nports); 80 80 }; 81 81 82 82 /* Store GPIO context across system-wide suspend/resume transitions */ ··· 114 114 struct dwapb_gpio { 115 115 struct device *dev; 116 116 void __iomem *regs; 117 - struct dwapb_gpio_port *ports; 118 117 unsigned int nr_ports; 119 118 unsigned int flags; 120 119 struct reset_control *rst; 121 120 struct clk_bulk_data clks[DWAPB_NR_CLOCKS]; 121 + struct dwapb_gpio_port ports[] __counted_by(nr_ports); 122 122 }; 123 123 124 124 static inline u32 gpio_reg_v2_convert(unsigned int offset) ··· 585 585 if (nports == 0) 586 586 return ERR_PTR(-ENODEV); 587 587 588 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 588 + pdata = devm_kzalloc(dev, struct_size(pdata, properties, nports), GFP_KERNEL); 589 589 if (!pdata) 590 - return ERR_PTR(-ENOMEM); 591 - 592 - pdata->properties = devm_kcalloc(dev, nports, sizeof(*pp), GFP_KERNEL); 593 - if (!pdata->properties) 594 590 return ERR_PTR(-ENOMEM); 595 591 596 592 pdata->nports = nports; ··· 710 714 if (IS_ERR(pdata)) 711 715 return PTR_ERR(pdata); 712 716 713 - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 717 + gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, ports, pdata->nports), GFP_KERNEL); 714 718 if (!gpio) 715 719 return -ENOMEM; 716 720 717 - gpio->dev = &pdev->dev; 718 721 gpio->nr_ports = pdata->nports; 722 + gpio->dev = &pdev->dev; 719 723 720 724 err = dwapb_get_reset(gpio); 721 725 if (err) 722 726 return err; 723 - 724 - gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, 725 - sizeof(*gpio->ports), GFP_KERNEL); 726 - if (!gpio->ports) 727 - return -ENOMEM; 728 727 729 728 gpio->regs = devm_platform_ioremap_resource(pdev, 0); 730 729 if (IS_ERR(gpio->regs))
+4 -9
drivers/gpio/gpio-htc-egpio.c
··· 46 46 uint chained_irq; 47 47 48 48 /* egpio info */ 49 - struct egpio_chip *chip; 50 49 int nchips; 50 + struct egpio_chip chip[] __counted_by(nchips); 51 51 }; 52 52 53 53 static inline void egpio_writew(u16 value, struct egpio_info *ei, int reg) ··· 270 270 int i; 271 271 272 272 /* Initialize ei data structure. */ 273 - ei = devm_kzalloc(&pdev->dev, sizeof(*ei), GFP_KERNEL); 273 + ei = devm_kzalloc(&pdev->dev, struct_size(ei, chip, pdata->num_chips), GFP_KERNEL); 274 274 if (!ei) 275 275 return -ENOMEM; 276 + 277 + ei->nchips = pdata->num_chips; 276 278 277 279 spin_lock_init(&ei->lock); 278 280 ··· 303 301 ei->reg_mask = (1 << pdata->reg_width) - 1; 304 302 305 303 platform_set_drvdata(pdev, ei); 306 - 307 - ei->nchips = pdata->num_chips; 308 - ei->chip = devm_kcalloc(&pdev->dev, 309 - ei->nchips, sizeof(struct egpio_chip), 310 - GFP_KERNEL); 311 - if (!ei->chip) 312 - return -ENOMEM; 313 304 314 305 for (i = 0; i < ei->nchips; i++) { 315 306 ei->chip[i].reg_start = pdata->chip[i].reg_start;
+276 -13
drivers/gpio/gpio-kempld.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/bitops.h> 13 13 #include <linux/errno.h> 14 + #include <linux/interrupt.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/gpio/driver.h> 16 17 #include <linux/mfd/kempld.h> 17 18 18 19 #define KEMPLD_GPIO_MAX_NUM 16 19 20 #define KEMPLD_GPIO_MASK(x) (BIT((x) % 8)) 20 - #define KEMPLD_GPIO_DIR_NUM(x) (0x40 + (x) / 8) 21 - #define KEMPLD_GPIO_LVL_NUM(x) (0x42 + (x) / 8) 21 + #define KEMPLD_GPIO_DIR 0x40 22 + #define KEMPLD_GPIO_LVL 0x42 23 + #define KEMPLD_GPIO_STS 0x44 22 24 #define KEMPLD_GPIO_EVT_LVL_EDGE 0x46 25 + #define KEMPLD_GPIO_EVT_LOW_HIGH 0x48 23 26 #define KEMPLD_GPIO_IEN 0x4A 27 + #define KEMPLD_GPIO_OUT_LVL 0x4E 28 + 29 + /* The IRQ to use if none was configured in the BIOS */ 30 + static unsigned int gpio_irq; 31 + module_param_hw(gpio_irq, uint, irq, 0444); 32 + MODULE_PARM_DESC(gpio_irq, "Set legacy GPIO IRQ (1-15)"); 24 33 25 34 struct kempld_gpio_data { 26 35 struct gpio_chip chip; 27 36 struct kempld_device_data *pld; 37 + u8 out_lvl_reg; 38 + 39 + struct mutex irq_lock; 40 + u16 ien; 41 + u16 evt_low_high; 42 + u16 evt_lvl_edge; 28 43 }; 29 44 30 45 /* ··· 47 32 * kempld_get_mutex must be called prior to calling this function. 48 33 */ 49 34 static void kempld_gpio_bitop(struct kempld_device_data *pld, 50 - u8 reg, u8 bit, u8 val) 35 + u8 reg, unsigned int bit, bool val) 51 36 { 52 37 u8 status; 53 38 54 - status = kempld_read8(pld, reg); 39 + status = kempld_read8(pld, reg + (bit / 8)); 55 40 if (val) 56 41 status |= KEMPLD_GPIO_MASK(bit); 57 42 else 58 43 status &= ~KEMPLD_GPIO_MASK(bit); 59 - kempld_write8(pld, reg, status); 44 + kempld_write8(pld, reg + (bit / 8), status); 60 45 } 61 46 62 - static int kempld_gpio_get_bit(struct kempld_device_data *pld, u8 reg, u8 bit) 47 + static int kempld_gpio_get_bit(struct kempld_device_data *pld, 48 + u8 reg, unsigned int bit) 63 49 { 64 50 u8 status; 65 51 66 52 kempld_get_mutex(pld); 67 - status = kempld_read8(pld, reg); 53 + status = kempld_read8(pld, reg + (bit / 8)); 68 54 kempld_release_mutex(pld); 69 55 70 56 return !!(status & KEMPLD_GPIO_MASK(bit)); ··· 76 60 struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 77 61 struct kempld_device_data *pld = gpio->pld; 78 62 79 - return !!kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset); 63 + return !!kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL, offset); 64 + } 65 + 66 + static int kempld_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, 67 + unsigned long *bits) 68 + { 69 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 70 + struct kempld_device_data *pld = gpio->pld; 71 + u8 reg = KEMPLD_GPIO_LVL; 72 + unsigned int shift; 73 + 74 + bits[0] &= ~mask[0]; 75 + 76 + kempld_get_mutex(pld); 77 + 78 + /* Try to reduce to a single 8 bits access if possible */ 79 + for (shift = 0; shift < gpio->chip.ngpio; shift += 8, reg++) { 80 + unsigned long msk = (mask[0] >> shift) & 0xff; 81 + 82 + if (!msk) 83 + continue; 84 + 85 + bits[0] |= (kempld_read8(pld, reg) & msk) << shift; 86 + } 87 + 88 + kempld_release_mutex(pld); 89 + 90 + return 0; 80 91 } 81 92 82 93 static int kempld_gpio_set(struct gpio_chip *chip, unsigned int offset, ··· 113 70 struct kempld_device_data *pld = gpio->pld; 114 71 115 72 kempld_get_mutex(pld); 116 - kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), offset, value); 73 + kempld_gpio_bitop(pld, gpio->out_lvl_reg, offset, value); 74 + kempld_release_mutex(pld); 75 + 76 + return 0; 77 + } 78 + 79 + static int kempld_gpio_set_multiple(struct gpio_chip *chip, 80 + unsigned long *mask, unsigned long *bits) 81 + { 82 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 83 + struct kempld_device_data *pld = gpio->pld; 84 + u8 reg = gpio->out_lvl_reg; 85 + unsigned int shift; 86 + 87 + kempld_get_mutex(pld); 88 + 89 + /* Try to reduce to a single 8 bits access if possible */ 90 + for (shift = 0; shift < gpio->chip.ngpio; shift += 8, reg++) { 91 + u8 val, msk = mask[0] >> shift; 92 + 93 + if (!msk) 94 + continue; 95 + 96 + if (msk != 0xFF) 97 + val = kempld_read8(pld, reg) & ~msk; 98 + else 99 + val = 0; 100 + 101 + val |= (bits[0] >> shift) & msk; 102 + kempld_write8(pld, reg, val); 103 + } 104 + 117 105 kempld_release_mutex(pld); 118 106 119 107 return 0; ··· 156 82 struct kempld_device_data *pld = gpio->pld; 157 83 158 84 kempld_get_mutex(pld); 159 - kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), offset, 0); 85 + kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR, offset, 0); 160 86 kempld_release_mutex(pld); 161 87 162 88 return 0; ··· 169 95 struct kempld_device_data *pld = gpio->pld; 170 96 171 97 kempld_get_mutex(pld); 172 - kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), offset, value); 173 - kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), offset, 1); 98 + kempld_gpio_bitop(pld, gpio->out_lvl_reg, offset, value); 99 + kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR, offset, 1); 174 100 kempld_release_mutex(pld); 175 101 176 102 return 0; ··· 181 107 struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 182 108 struct kempld_device_data *pld = gpio->pld; 183 109 184 - if (kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset)) 110 + if (kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR, offset)) 185 111 return GPIO_LINE_DIRECTION_OUT; 186 112 187 113 return GPIO_LINE_DIRECTION_IN; ··· 207 133 return evt ? __ffs(evt) : 16; 208 134 } 209 135 136 + static void kempld_irq_mask(struct irq_data *data) 137 + { 138 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 139 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 140 + 141 + gpio->ien &= ~BIT(irqd_to_hwirq(data)); 142 + gpiochip_disable_irq(chip, irqd_to_hwirq(data)); 143 + } 144 + 145 + static void kempld_irq_unmask(struct irq_data *data) 146 + { 147 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 148 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 149 + 150 + gpiochip_enable_irq(chip, irqd_to_hwirq(data)); 151 + gpio->ien |= BIT(irqd_to_hwirq(data)); 152 + } 153 + 154 + static int kempld_irq_set_type(struct irq_data *data, unsigned int type) 155 + { 156 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 157 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 158 + 159 + switch (type) { 160 + case IRQ_TYPE_EDGE_RISING: 161 + gpio->evt_low_high |= BIT(data->hwirq); 162 + gpio->evt_lvl_edge |= BIT(data->hwirq); 163 + break; 164 + case IRQ_TYPE_EDGE_FALLING: 165 + gpio->evt_low_high &= ~BIT(data->hwirq); 166 + gpio->evt_lvl_edge |= BIT(data->hwirq); 167 + break; 168 + case IRQ_TYPE_LEVEL_HIGH: 169 + gpio->evt_low_high |= BIT(data->hwirq); 170 + gpio->evt_lvl_edge &= ~BIT(data->hwirq); 171 + break; 172 + case IRQ_TYPE_LEVEL_LOW: 173 + gpio->evt_low_high &= ~BIT(data->hwirq); 174 + gpio->evt_lvl_edge &= ~BIT(data->hwirq); 175 + break; 176 + default: 177 + return -EINVAL; 178 + } 179 + 180 + return 0; 181 + } 182 + 183 + static void kempld_irq_bus_lock(struct irq_data *data) 184 + { 185 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 186 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 187 + 188 + mutex_lock(&gpio->irq_lock); 189 + } 190 + 191 + static void kempld_irq_bus_sync_unlock(struct irq_data *data) 192 + { 193 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 194 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 195 + struct kempld_device_data *pld = gpio->pld; 196 + 197 + kempld_get_mutex(pld); 198 + kempld_write16(pld, KEMPLD_GPIO_EVT_LVL_EDGE, gpio->evt_lvl_edge); 199 + kempld_write16(pld, KEMPLD_GPIO_EVT_LOW_HIGH, gpio->evt_low_high); 200 + kempld_write16(pld, KEMPLD_GPIO_IEN, gpio->ien); 201 + kempld_release_mutex(pld); 202 + 203 + mutex_unlock(&gpio->irq_lock); 204 + } 205 + 206 + static const struct irq_chip kempld_irqchip = { 207 + .name = "kempld-gpio", 208 + .irq_mask = kempld_irq_mask, 209 + .irq_unmask = kempld_irq_unmask, 210 + .irq_set_type = kempld_irq_set_type, 211 + .irq_bus_lock = kempld_irq_bus_lock, 212 + .irq_bus_sync_unlock = kempld_irq_bus_sync_unlock, 213 + .flags = IRQCHIP_IMMUTABLE, 214 + GPIOCHIP_IRQ_RESOURCE_HELPERS, 215 + }; 216 + 217 + static irqreturn_t kempld_gpio_irq_handler(int irq, void *data) 218 + { 219 + struct kempld_gpio_data *gpio = data; 220 + struct gpio_chip *chip = &gpio->chip; 221 + unsigned int pin, child_irq; 222 + unsigned long status; 223 + 224 + kempld_get_mutex(gpio->pld); 225 + 226 + status = kempld_read16(gpio->pld, KEMPLD_GPIO_STS); 227 + if (status) 228 + kempld_write16(gpio->pld, KEMPLD_GPIO_STS, status); 229 + 230 + kempld_release_mutex(gpio->pld); 231 + 232 + status &= gpio->ien; 233 + if (!status) 234 + return IRQ_NONE; 235 + 236 + for_each_set_bit(pin, &status, chip->ngpio) { 237 + child_irq = irq_find_mapping(chip->irq.domain, pin); 238 + handle_nested_irq(child_irq); 239 + } 240 + 241 + return IRQ_HANDLED; 242 + } 243 + 244 + static int kempld_gpio_irq_init(struct device *dev, 245 + struct kempld_gpio_data *gpio) 246 + { 247 + struct kempld_device_data *pld = gpio->pld; 248 + struct gpio_chip *chip = &gpio->chip; 249 + struct gpio_irq_chip *girq; 250 + unsigned int irq; 251 + int ret; 252 + 253 + /* Get the IRQ configured by the BIOS in the PLD */ 254 + kempld_get_mutex(pld); 255 + irq = kempld_read8(pld, KEMPLD_IRQ_GPIO); 256 + kempld_release_mutex(pld); 257 + 258 + if (irq == 0xff) { 259 + dev_info(dev, "GPIO controller has no IRQ support\n"); 260 + return 0; 261 + } 262 + 263 + /* Allow overriding the IRQ with the module parameter */ 264 + if (gpio_irq > 0) { 265 + dev_warn(dev, "Forcing IRQ to %d\n", gpio_irq); 266 + irq &= ~KEMPLD_IRQ_GPIO_MASK; 267 + irq |= gpio_irq & KEMPLD_IRQ_GPIO_MASK; 268 + } 269 + 270 + if (!(irq & KEMPLD_IRQ_GPIO_MASK)) { 271 + dev_warn(dev, "No IRQ configured\n"); 272 + return 0; 273 + } 274 + 275 + /* Get the current config, disable all child interrupts, clear them 276 + * and set the parent IRQ 277 + */ 278 + kempld_get_mutex(pld); 279 + gpio->evt_low_high = kempld_read16(pld, KEMPLD_GPIO_EVT_LOW_HIGH); 280 + gpio->evt_lvl_edge = kempld_read16(pld, KEMPLD_GPIO_EVT_LVL_EDGE); 281 + kempld_write16(pld, KEMPLD_GPIO_IEN, 0); 282 + kempld_write16(pld, KEMPLD_GPIO_STS, 0xFFFF); 283 + kempld_write16(pld, KEMPLD_IRQ_GPIO, irq); 284 + kempld_release_mutex(pld); 285 + 286 + girq = &chip->irq; 287 + gpio_irq_chip_set_chip(girq, &kempld_irqchip); 288 + 289 + girq->parent_handler = NULL; 290 + girq->num_parents = 0; 291 + girq->parents = NULL; 292 + girq->default_type = IRQ_TYPE_NONE; 293 + girq->handler = handle_simple_irq; 294 + girq->threaded = true; 295 + 296 + mutex_init(&gpio->irq_lock); 297 + 298 + ret = devm_request_threaded_irq(dev, irq & KEMPLD_IRQ_GPIO_MASK, 299 + NULL, kempld_gpio_irq_handler, 300 + IRQF_ONESHOT, chip->label, 301 + gpio); 302 + if (ret) { 303 + dev_err(dev, "failed to request irq %d\n", irq); 304 + return ret; 305 + } 306 + 307 + return 0; 308 + } 309 + 210 310 static int kempld_gpio_probe(struct platform_device *pdev) 211 311 { 212 312 struct device *dev = &pdev->dev; ··· 400 152 if (!gpio) 401 153 return -ENOMEM; 402 154 155 + /* Starting with version 2.8 there is a dedicated register for the 156 + * output state, earlier versions share the register used to read 157 + * the line level. 158 + */ 159 + if (pld->info.spec_major > 2 || pld->info.spec_minor >= 8) 160 + gpio->out_lvl_reg = KEMPLD_GPIO_OUT_LVL; 161 + else 162 + gpio->out_lvl_reg = KEMPLD_GPIO_LVL; 163 + 403 164 gpio->pld = pld; 404 165 405 166 platform_set_drvdata(pdev, gpio); ··· 426 169 chip->direction_output = kempld_gpio_direction_output; 427 170 chip->get_direction = kempld_gpio_get_direction; 428 171 chip->get = kempld_gpio_get; 172 + chip->get_multiple = kempld_gpio_get_multiple; 429 173 chip->set = kempld_gpio_set; 174 + chip->set_multiple = kempld_gpio_set_multiple; 430 175 chip->ngpio = kempld_gpio_pincount(pld); 431 176 if (chip->ngpio == 0) { 432 177 dev_err(dev, "No GPIO pins detected\n"); 433 178 return -ENODEV; 434 179 } 180 + 181 + ret = kempld_gpio_irq_init(dev, gpio); 182 + if (ret) 183 + return ret; 435 184 436 185 ret = devm_gpiochip_add_data(dev, chip, gpio); 437 186 if (ret) {
+1 -1
drivers/gpio/gpio-lp873x.c
··· 55 55 if (ret < 0) 56 56 return ret; 57 57 58 - return val & BIT(offset * BITS_PER_GPO); 58 + return !!(val & BIT(offset * BITS_PER_GPO)); 59 59 } 60 60 61 61 static int lp873x_gpio_set(struct gpio_chip *chip, unsigned int offset,
+12 -12
drivers/gpio/gpio-max732x.c
··· 10 10 * Derived from drivers/gpio/pca953x.c 11 11 */ 12 12 13 - #include <linux/module.h> 13 + #include <linux/cleanup.h> 14 + #include <linux/err.h> 15 + #include <linux/device.h> 16 + #include <linux/gpio/driver.h> 17 + #include <linux/i2c.h> 14 18 #include <linux/init.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/module.h> 21 + #include <linux/mutex.h> 22 + #include <linux/platform_data/max732x.h> 15 23 #include <linux/slab.h> 16 24 #include <linux/string.h> 17 - #include <linux/gpio/driver.h> 18 - #include <linux/interrupt.h> 19 - #include <linux/i2c.h> 20 - #include <linux/platform_data/max732x.h> 21 25 22 26 /* 23 27 * Each port of MAX732x (including MAX7319) falls into one of the ··· 211 207 uint8_t reg_out; 212 208 int ret; 213 209 214 - mutex_lock(&chip->lock); 210 + guard(mutex)(&chip->lock); 215 211 216 212 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; 217 213 reg_out = (reg_out & ~mask) | (val & mask); 218 214 219 215 ret = max732x_writeb(chip, is_group_a(chip, off), reg_out); 220 216 if (ret < 0) 221 - goto out; 217 + return; 222 218 223 219 /* update the shadow register then */ 224 220 if (off > 7) 225 221 chip->reg_out[1] = reg_out; 226 222 else 227 223 chip->reg_out[0] = reg_out; 228 - out: 229 - mutex_unlock(&chip->lock); 230 224 } 231 225 232 226 static int max732x_gpio_set_value(struct gpio_chip *gc, unsigned int off, ··· 331 329 if (chip->irq_features == INT_NO_MASK) 332 330 return; 333 331 334 - mutex_lock(&chip->lock); 332 + guard(mutex)(&chip->lock); 335 333 336 334 switch (chip->irq_features) { 337 335 case INT_INDEP_MASK: ··· 344 342 max732x_writeb(chip, 1, (uint8_t)msg); 345 343 break; 346 344 } 347 - 348 - mutex_unlock(&chip->lock); 349 345 } 350 346 351 347 static void max732x_irq_mask(struct irq_data *d)
+1 -3
drivers/gpio/gpio-mmio.c
··· 42 42 43 43 #include <linux/bitops.h> 44 44 #include <linux/cleanup.h> 45 - #include <linux/compiler.h> 46 45 #include <linux/err.h> 47 - #include <linux/init.h> 48 46 #include <linux/io.h> 49 47 #include <linux/ioport.h> 48 + #include <linux/limits.h> 50 49 #include <linux/log2.h> 51 50 #include <linux/mod_devicetable.h> 52 51 #include <linux/module.h> 53 52 #include <linux/pinctrl/consumer.h> 54 53 #include <linux/platform_device.h> 55 54 #include <linux/property.h> 56 - #include <linux/slab.h> 57 55 #include <linux/spinlock.h> 58 56 #include <linux/types.h> 59 57
+1 -12
drivers/gpio/gpio-mpsse.c
··· 548 548 ida_free(&gpio_mpsse_ida, priv->id); 549 549 } 550 550 551 - static void gpio_mpsse_usb_put_dev(void *data) 552 - { 553 - struct mpsse_priv *priv = data; 554 - 555 - usb_put_dev(priv->udev); 556 - } 557 - 558 551 static int mpsse_init_valid_mask(struct gpio_chip *chip, 559 552 unsigned long *valid_mask, 560 553 unsigned int ngpios) ··· 591 598 592 599 INIT_LIST_HEAD(&priv->workers); 593 600 594 - priv->udev = usb_get_dev(interface_to_usbdev(interface)); 595 - err = devm_add_action_or_reset(dev, gpio_mpsse_usb_put_dev, priv); 596 - if (err) 597 - return err; 598 - 601 + priv->udev = interface_to_usbdev(interface); 599 602 priv->intf = interface; 600 603 priv->intf_id = interface->cur_altsetting->desc.bInterfaceNumber; 601 604
+323
drivers/gpio/gpio-novalake-events.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Intel Nova Lake GPIO-signaled ACPI events driver 4 + * 5 + * Copyright (c) 2026, Intel Corporation. 6 + * 7 + * Author: Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com> 8 + * 9 + * Intel client platforms released in 2026 and later (starting with Intel Nova 10 + * Lake) support two modes of handling ACPI General Purpose Events (GPE): 11 + * exposed GPIO interrupt mode and legacy mode. 12 + * 13 + * By default, the platform uses legacy mode, handling GPEs as usual. If this 14 + * driver is installed, it signals to the platform (on every boot) that exposed 15 + * GPIO interrupt mode is supported. The platform then switches to exposed 16 + * mode, which takes effect on next boot. From the user perspective, this 17 + * change is transparent. 18 + * 19 + * However, if driver is uninstalled while in exposed interrupt mode, GPEs will 20 + * _not_ be handled until platform falls back to legacy mode. This means that 21 + * USB keyboard, mouse might not function properly for the fallback duration. 22 + * Fallback requires two reboots to take effect: on first reboot, platform no 23 + * longer receives signal from this driver and switches to legacy mode, which 24 + * takes effect on second boot. 25 + * 26 + * Example ACPI event: Power Management Event coming from motherboard PCH, 27 + * waking system from sleep following USB mouse hotplug. 28 + * 29 + * This driver supports up to 128 GPIO pins in each GPE block, per ACPI 30 + * specification v6.6 section 5.6.4. 31 + */ 32 + 33 + #include <linux/acpi.h> 34 + #include <linux/bitops.h> 35 + #include <linux/cleanup.h> 36 + #include <linux/device.h> 37 + #include <linux/errno.h> 38 + #include <linux/gfp_types.h> 39 + #include <linux/interrupt.h> 40 + #include <linux/io.h> 41 + #include <linux/ioport.h> 42 + #include <linux/irq.h> 43 + #include <linux/module.h> 44 + #include <linux/platform_device.h> 45 + #include <linux/spinlock.h> 46 + #include <linux/types.h> 47 + #include <linux/uuid.h> 48 + 49 + #include <linux/gpio/driver.h> 50 + 51 + /* 52 + * GPE block has two registers, each register takes half the block size. 53 + * Convert size to bits to get total GPIO pin count. 54 + */ 55 + #define GPE_BLK_REG_SIZE(block_size) ((block_size) / 2) 56 + #define GPE_REG_PIN_COUNT(block_size) BYTES_TO_BITS(GPE_BLK_REG_SIZE(block_size)) 57 + #define GPE_STS_REG_OFFSET 0 58 + #define GPE_EN_REG_OFFSET(block_size) GPE_BLK_REG_SIZE(block_size) 59 + 60 + /** 61 + * struct nvl_gpio - Intel Nova Lake GPIO driver state 62 + * @gc: GPIO controller interface 63 + * @reg_base: Base address of the GPE registers 64 + * @lock: Guard register access 65 + * @blk_size: GPE block length 66 + */ 67 + struct nvl_gpio { 68 + struct gpio_chip gc; 69 + void __iomem *reg_base; 70 + raw_spinlock_t lock; 71 + size_t blk_size; 72 + }; 73 + 74 + static void __iomem *nvl_gpio_get_byte_addr(struct nvl_gpio *priv, 75 + unsigned int reg_offset, 76 + unsigned long gpio) 77 + { 78 + return priv->reg_base + reg_offset + gpio; 79 + } 80 + 81 + static int nvl_gpio_get(struct gpio_chip *gc, unsigned int gpio) 82 + { 83 + struct nvl_gpio *priv = gpiochip_get_data(gc); 84 + unsigned int byte_idx = gpio / BITS_PER_BYTE; 85 + unsigned int bit_idx = gpio % BITS_PER_BYTE; 86 + void __iomem *addr; 87 + u8 reg; 88 + 89 + addr = nvl_gpio_get_byte_addr(priv, GPE_STS_REG_OFFSET, byte_idx); 90 + 91 + guard(raw_spinlock_irqsave)(&priv->lock); 92 + 93 + reg = ioread8(addr); 94 + 95 + return !!(reg & BIT(bit_idx)); 96 + } 97 + 98 + static const struct gpio_chip nvl_gpio_chip = { 99 + .owner = THIS_MODULE, 100 + .get = nvl_gpio_get, 101 + }; 102 + 103 + static int nvl_gpio_irq_set_type(struct irq_data *d, unsigned int type) 104 + { 105 + if (type & IRQ_TYPE_EDGE_BOTH) 106 + irq_set_handler_locked(d, handle_edge_irq); 107 + else if (type & IRQ_TYPE_LEVEL_MASK) 108 + irq_set_handler_locked(d, handle_level_irq); 109 + 110 + return 0; 111 + } 112 + 113 + static void nvl_gpio_irq_mask_unmask(struct gpio_chip *gc, unsigned long hwirq, 114 + bool mask) 115 + { 116 + struct nvl_gpio *priv = gpiochip_get_data(gc); 117 + unsigned int byte_idx = hwirq / BITS_PER_BYTE; 118 + unsigned int bit_idx = hwirq % BITS_PER_BYTE; 119 + void __iomem *addr; 120 + u8 reg; 121 + 122 + addr = nvl_gpio_get_byte_addr(priv, GPE_EN_REG_OFFSET(priv->blk_size), byte_idx); 123 + 124 + guard(raw_spinlock_irqsave)(&priv->lock); 125 + 126 + reg = ioread8(addr); 127 + if (mask) 128 + reg &= ~BIT(bit_idx); 129 + else 130 + reg |= BIT(bit_idx); 131 + iowrite8(reg, addr); 132 + } 133 + 134 + static void nvl_gpio_irq_unmask(struct irq_data *d) 135 + { 136 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 137 + irq_hw_number_t hwirq = irqd_to_hwirq(d); 138 + 139 + gpiochip_enable_irq(gc, hwirq); 140 + nvl_gpio_irq_mask_unmask(gc, hwirq, false); 141 + } 142 + 143 + static void nvl_gpio_irq_mask(struct irq_data *d) 144 + { 145 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 146 + irq_hw_number_t hwirq = irqd_to_hwirq(d); 147 + 148 + nvl_gpio_irq_mask_unmask(gc, hwirq, true); 149 + gpiochip_disable_irq(gc, hwirq); 150 + } 151 + 152 + static void nvl_gpio_irq_ack(struct irq_data *d) 153 + { 154 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 155 + struct nvl_gpio *priv = gpiochip_get_data(gc); 156 + irq_hw_number_t hwirq = irqd_to_hwirq(d); 157 + unsigned int byte_idx = hwirq / BITS_PER_BYTE; 158 + unsigned int bit_idx = hwirq % BITS_PER_BYTE; 159 + void __iomem *addr; 160 + u8 reg; 161 + 162 + addr = nvl_gpio_get_byte_addr(priv, GPE_STS_REG_OFFSET, byte_idx); 163 + 164 + guard(raw_spinlock_irqsave)(&priv->lock); 165 + 166 + reg = ioread8(addr); 167 + reg |= BIT(bit_idx); 168 + iowrite8(reg, addr); 169 + } 170 + 171 + static const struct irq_chip nvl_gpio_irq_chip = { 172 + .name = "gpio-novalake", 173 + .irq_ack = nvl_gpio_irq_ack, 174 + .irq_mask = nvl_gpio_irq_mask, 175 + .irq_unmask = nvl_gpio_irq_unmask, 176 + .irq_set_type = nvl_gpio_irq_set_type, 177 + .flags = IRQCHIP_IMMUTABLE, 178 + GPIOCHIP_IRQ_RESOURCE_HELPERS, 179 + }; 180 + 181 + static irqreturn_t nvl_gpio_irq(int irq, void *data) 182 + { 183 + struct nvl_gpio *priv = data; 184 + const size_t block_size = priv->blk_size; 185 + unsigned int handled = 0; 186 + 187 + for (unsigned int i = 0; i < block_size; i++) { 188 + const void __iomem *reg = priv->reg_base + i; 189 + unsigned long pending; 190 + unsigned long enabled; 191 + unsigned int bit_idx; 192 + 193 + scoped_guard(raw_spinlock, &priv->lock) { 194 + pending = ioread8(reg + GPE_STS_REG_OFFSET); 195 + enabled = ioread8(reg + GPE_EN_REG_OFFSET(block_size)); 196 + } 197 + pending &= enabled; 198 + 199 + for_each_set_bit(bit_idx, &pending, BITS_PER_BYTE) { 200 + unsigned int hwirq = i * BITS_PER_BYTE + bit_idx; 201 + 202 + generic_handle_domain_irq(priv->gc.irq.domain, hwirq); 203 + } 204 + 205 + handled += pending ? 1 : 0; 206 + } 207 + 208 + return IRQ_RETVAL(handled); 209 + } 210 + 211 + /* UUID for GPE device _DSM: 079406e6-bdea-49cf-8563-03e2811901cb */ 212 + static const guid_t nvl_gpe_dsm_guid = 213 + GUID_INIT(0x079406e6, 0xbdea, 0x49cf, 214 + 0x85, 0x63, 0x03, 0xe2, 0x81, 0x19, 0x01, 0xcb); 215 + 216 + #define DSM_GPE_MODE_REV 1 217 + #define DSM_GPE_MODE_FN_INDEX 1 218 + #define DSM_ENABLE_GPE_MODE 1 219 + 220 + static int nvl_acpi_enable_gpe_mode(struct device *dev) 221 + { 222 + union acpi_object argv4[2]; 223 + union acpi_object *obj; 224 + 225 + argv4[0].type = ACPI_TYPE_PACKAGE; 226 + argv4[0].package.count = 1; 227 + argv4[0].package.elements = &argv4[1]; 228 + argv4[1].integer.type = ACPI_TYPE_INTEGER; 229 + argv4[1].integer.value = DSM_ENABLE_GPE_MODE; 230 + 231 + obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(dev), &nvl_gpe_dsm_guid, 232 + DSM_GPE_MODE_REV, DSM_GPE_MODE_FN_INDEX, 233 + argv4, ACPI_TYPE_BUFFER); 234 + if (!obj) 235 + return -EIO; 236 + ACPI_FREE(obj); 237 + 238 + return 0; 239 + } 240 + 241 + static int nvl_gpio_probe(struct platform_device *pdev) 242 + { 243 + struct device *dev = &pdev->dev; 244 + resource_size_t ioresource_size; 245 + struct gpio_irq_chip *girq; 246 + struct nvl_gpio *priv; 247 + struct resource *res; 248 + void __iomem *regs; 249 + int ret, irq; 250 + 251 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 252 + if (!res) 253 + return -ENXIO; 254 + 255 + /* 256 + * GPE block length should be non-negative multiple of two and allow up 257 + * to 128 pins. ACPI v6.6 section 5.2.9 and 5.6.4. 258 + */ 259 + ioresource_size = resource_size(res); 260 + if (!ioresource_size || ioresource_size % 2 || ioresource_size > 0x20) 261 + return dev_err_probe(dev, -EINVAL, 262 + "invalid GPE block length, resource: %pR\n", 263 + res); 264 + 265 + regs = devm_ioport_map(dev, res->start, ioresource_size); 266 + if (!regs) 267 + return -ENOMEM; 268 + 269 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 270 + if (!priv) 271 + return -ENOMEM; 272 + raw_spin_lock_init(&priv->lock); 273 + 274 + priv->reg_base = regs; 275 + priv->blk_size = ioresource_size; 276 + 277 + irq = platform_get_irq(pdev, 0); 278 + if (irq < 0) 279 + return irq; 280 + 281 + ret = devm_request_irq(dev, irq, nvl_gpio_irq, IRQF_SHARED, dev_name(dev), priv); 282 + if (ret) 283 + return ret; 284 + 285 + priv->gc = nvl_gpio_chip; 286 + priv->gc.label = dev_name(dev); 287 + priv->gc.parent = dev; 288 + priv->gc.ngpio = GPE_REG_PIN_COUNT(priv->blk_size); 289 + priv->gc.base = -1; 290 + 291 + girq = &priv->gc.irq; 292 + gpio_irq_chip_set_chip(girq, &nvl_gpio_irq_chip); 293 + girq->parent_handler = NULL; 294 + girq->num_parents = 0; 295 + girq->parents = NULL; 296 + girq->default_type = IRQ_TYPE_NONE; 297 + girq->handler = handle_bad_irq; 298 + 299 + ret = devm_gpiochip_add_data(dev, &priv->gc, priv); 300 + if (ret) 301 + return ret; 302 + 303 + return nvl_acpi_enable_gpe_mode(dev); 304 + } 305 + 306 + static const struct acpi_device_id nvl_gpio_acpi_match[] = { 307 + { "INTC1114" }, 308 + {} 309 + }; 310 + MODULE_DEVICE_TABLE(acpi, nvl_gpio_acpi_match); 311 + 312 + static struct platform_driver nvl_gpio_driver = { 313 + .driver = { 314 + .name = "gpio-novalake-events", 315 + .acpi_match_table = nvl_gpio_acpi_match, 316 + }, 317 + .probe = nvl_gpio_probe, 318 + }; 319 + module_platform_driver(nvl_gpio_driver); 320 + 321 + MODULE_LICENSE("GPL"); 322 + MODULE_AUTHOR("Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com>"); 323 + MODULE_DESCRIPTION("Intel Nova Lake ACPI GPIO events driver");
+4
drivers/gpio/gpio-realtek-otto.c
··· 351 351 { 352 352 .compatible = "realtek,rtl9310-gpio", 353 353 }, 354 + { 355 + .compatible = "realtek,rtl9607-gpio", 356 + .data = (void *)GPIO_PORTS_REVERSED, 357 + }, 354 358 {} 355 359 }; 356 360 MODULE_DEVICE_TABLE(of, realtek_gpio_of_match);
+1 -1
drivers/gpio/gpio-rockchip.c
··· 582 582 bank->gpio_chip = rockchip_gpiolib_chip; 583 583 584 584 gc = &bank->gpio_chip; 585 - gc->base = bank->pin_base; 585 + gc->base = -1; 586 586 gc->ngpio = bank->nr_pins; 587 587 gc->label = bank->name; 588 588 gc->parent = bank->dev;
+119 -122
drivers/gpio/gpio-sim.c
··· 36 36 #include <linux/sysfs.h> 37 37 #include <linux/types.h> 38 38 39 - #include "dev-sync-probe.h" 40 - 41 39 #define GPIO_SIM_NGPIO_MAX 1024 42 40 #define GPIO_SIM_PROP_MAX 5 /* Max 4 properties + sentinel. */ 41 + #define GPIO_SIM_HOG_PROP_MAX 5 43 42 #define GPIO_SIM_NUM_ATTRS 3 /* value, pull and sentinel */ 44 43 45 44 static DEFINE_IDA(gpio_sim_ida); ··· 544 545 }; 545 546 546 547 struct gpio_sim_device { 547 - struct dev_sync_probe_data probe_data; 548 + struct platform_device *pdev; 548 549 struct config_group group; 549 550 550 551 int id; ··· 559 560 * object too. 560 561 */ 561 562 struct mutex lock; 562 - 563 - struct gpiod_hog *hogs; 564 563 565 564 struct list_head bank_list; 566 565 }; ··· 652 655 653 656 char *name; 654 657 int dir; 658 + bool active_low; 655 659 }; 656 660 657 661 static struct gpio_sim_hog *to_gpio_sim_hog(struct config_item *item) ··· 671 673 { 672 674 lockdep_assert_held(&dev->lock); 673 675 674 - return !!dev->probe_data.pdev; 676 + return !!dev->pdev; 675 677 } 676 678 677 679 static char *gpio_sim_strdup_trimmed(const char *str, size_t count) ··· 693 695 694 696 guard(mutex)(&dev->lock); 695 697 696 - pdev = dev->probe_data.pdev; 698 + pdev = dev->pdev; 697 699 if (pdev) 698 700 return sprintf(page, "%s\n", dev_name(&pdev->dev)); 699 701 ··· 772 774 } 773 775 } 774 776 775 - static void gpio_sim_remove_hogs(struct gpio_sim_device *dev) 776 - { 777 - struct gpiod_hog *hog; 778 - 779 - if (!dev->hogs) 780 - return; 781 - 782 - gpiod_remove_hogs(dev->hogs); 783 - 784 - for (hog = dev->hogs; hog->chip_label; hog++) { 785 - kfree(hog->chip_label); 786 - kfree(hog->line_name); 787 - } 788 - 789 - kfree(dev->hogs); 790 - dev->hogs = NULL; 791 - } 792 - 793 - static int gpio_sim_add_hogs(struct gpio_sim_device *dev) 794 - { 795 - unsigned int num_hogs = 0, idx = 0; 796 - struct gpio_sim_bank *bank; 797 - struct gpio_sim_line *line; 798 - struct gpiod_hog *hog; 799 - 800 - list_for_each_entry(bank, &dev->bank_list, siblings) { 801 - list_for_each_entry(line, &bank->line_list, siblings) { 802 - if (line->offset >= bank->num_lines) 803 - continue; 804 - 805 - if (line->hog) 806 - num_hogs++; 807 - } 808 - } 809 - 810 - if (!num_hogs) 811 - return 0; 812 - 813 - /* Allocate one more for the sentinel. */ 814 - dev->hogs = kzalloc_objs(*dev->hogs, num_hogs + 1); 815 - if (!dev->hogs) 816 - return -ENOMEM; 817 - 818 - list_for_each_entry(bank, &dev->bank_list, siblings) { 819 - list_for_each_entry(line, &bank->line_list, siblings) { 820 - if (line->offset >= bank->num_lines) 821 - continue; 822 - 823 - if (!line->hog) 824 - continue; 825 - 826 - hog = &dev->hogs[idx++]; 827 - 828 - /* 829 - * We need to make this string manually because at this 830 - * point the device doesn't exist yet and so dev_name() 831 - * is not available. 832 - */ 833 - if (gpio_sim_bank_has_label(bank)) 834 - hog->chip_label = kstrdup(bank->label, 835 - GFP_KERNEL); 836 - else 837 - hog->chip_label = kasprintf(GFP_KERNEL, 838 - "gpio-sim.%u:%pfwP", 839 - dev->id, 840 - bank->swnode); 841 - if (!hog->chip_label) { 842 - gpio_sim_remove_hogs(dev); 843 - return -ENOMEM; 844 - } 845 - 846 - /* 847 - * We need to duplicate this because the hog config 848 - * item can be removed at any time (and we can't block 849 - * it) and gpiolib doesn't make a deep copy of the hog 850 - * data. 851 - */ 852 - if (line->hog->name) { 853 - hog->line_name = kstrdup(line->hog->name, 854 - GFP_KERNEL); 855 - if (!hog->line_name) { 856 - gpio_sim_remove_hogs(dev); 857 - return -ENOMEM; 858 - } 859 - } 860 - 861 - hog->chip_hwnum = line->offset; 862 - hog->dflags = line->hog->dir; 863 - } 864 - } 865 - 866 - gpiod_add_hogs(dev->hogs); 867 - 868 - return 0; 869 - } 870 - 871 777 static struct fwnode_handle * 872 778 gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank, 873 779 struct fwnode_handle *parent) ··· 819 917 return fwnode_create_software_node(properties, parent); 820 918 } 821 919 920 + static int gpio_sim_bank_add_hogs(struct gpio_sim_bank *bank) 921 + { 922 + struct property_entry properties[GPIO_SIM_HOG_PROP_MAX]; 923 + struct fwnode_handle *swnode; 924 + struct gpio_sim_line *line; 925 + struct gpio_sim_hog *hog; 926 + unsigned int idx; 927 + u32 gpios[2]; 928 + 929 + list_for_each_entry(line, &bank->line_list, siblings) { 930 + if (!line->hog) 931 + continue; 932 + 933 + hog = line->hog; 934 + 935 + gpios[0] = line->offset; 936 + gpios[1] = hog->active_low ? 1 : 0; 937 + 938 + memset(properties, 0, sizeof(properties)); 939 + 940 + idx = 0; 941 + properties[idx++] = PROPERTY_ENTRY_BOOL("gpio-hog"); 942 + properties[idx++] = PROPERTY_ENTRY_U32_ARRAY("gpios", gpios); 943 + properties[idx++] = PROPERTY_ENTRY_STRING("line-name", hog->name); 944 + 945 + switch (hog->dir) { 946 + case GPIOD_IN: 947 + properties[idx++] = PROPERTY_ENTRY_BOOL("input"); 948 + break; 949 + case GPIOD_OUT_HIGH: 950 + properties[idx++] = PROPERTY_ENTRY_BOOL("output-high"); 951 + break; 952 + case GPIOD_OUT_LOW: 953 + properties[idx++] = PROPERTY_ENTRY_BOOL("output-low"); 954 + break; 955 + default: 956 + /* Would have been validated at configfs store. */ 957 + WARN(1, "Unexpected hog direction value: %d", hog->dir); 958 + return -EINVAL; 959 + } 960 + 961 + swnode = fwnode_create_software_node(properties, bank->swnode); 962 + if (IS_ERR(swnode)) 963 + return PTR_ERR(swnode); 964 + } 965 + 966 + return 0; 967 + } 968 + 822 969 static void gpio_sim_remove_swnode_recursive(struct fwnode_handle *swnode) 823 970 { 824 971 struct fwnode_handle *child; 825 972 826 973 fwnode_for_each_child_node(swnode, child) 827 - fwnode_remove_software_node(child); 974 + gpio_sim_remove_swnode_recursive(child); 828 975 829 976 fwnode_remove_software_node(swnode); 830 977 } ··· 898 947 static int gpio_sim_device_activate(struct gpio_sim_device *dev) 899 948 { 900 949 struct platform_device_info pdevinfo; 950 + struct platform_device *pdev; 901 951 struct fwnode_handle *swnode; 902 952 struct gpio_sim_bank *bank; 903 953 int ret; ··· 926 974 bank->swnode = gpio_sim_make_bank_swnode(bank, swnode); 927 975 if (IS_ERR(bank->swnode)) { 928 976 ret = PTR_ERR(bank->swnode); 929 - gpio_sim_remove_swnode_recursive(swnode); 930 - return ret; 977 + goto err_remove_swnode; 931 978 } 932 - } 933 979 934 - ret = gpio_sim_add_hogs(dev); 935 - if (ret) { 936 - gpio_sim_remove_swnode_recursive(swnode); 937 - return ret; 980 + ret = gpio_sim_bank_add_hogs(bank); 981 + if (ret) 982 + goto err_remove_swnode; 938 983 } 939 984 940 985 pdevinfo.name = "gpio-sim"; 941 986 pdevinfo.fwnode = swnode; 942 987 pdevinfo.id = dev->id; 943 988 944 - ret = dev_sync_probe_register(&dev->probe_data, &pdevinfo); 945 - if (ret) { 946 - gpio_sim_remove_hogs(dev); 947 - gpio_sim_remove_swnode_recursive(swnode); 948 - return ret; 989 + pdev = platform_device_register_full(&pdevinfo); 990 + if (IS_ERR(pdev)) { 991 + ret = PTR_ERR(pdev); 992 + goto err_remove_swnode; 949 993 } 950 994 995 + wait_for_device_probe(); 996 + if (!device_is_bound(&pdev->dev)) { 997 + ret = -ENXIO; 998 + goto err_unregister_pdev; 999 + } 1000 + 1001 + dev->pdev = pdev; 951 1002 return 0; 1003 + 1004 + err_unregister_pdev: 1005 + platform_device_unregister(pdev); 1006 + err_remove_swnode: 1007 + gpio_sim_remove_swnode_recursive(swnode); 1008 + 1009 + return ret; 952 1010 } 953 1011 954 1012 static void gpio_sim_device_deactivate(struct gpio_sim_device *dev) ··· 967 1005 968 1006 lockdep_assert_held(&dev->lock); 969 1007 970 - swnode = dev_fwnode(&dev->probe_data.pdev->dev); 971 - dev_sync_probe_unregister(&dev->probe_data); 972 - gpio_sim_remove_hogs(dev); 1008 + swnode = dev_fwnode(&dev->pdev->dev); 1009 + platform_device_unregister(dev->pdev); 1010 + dev->pdev = NULL; 973 1011 gpio_sim_remove_swnode_recursive(swnode); 974 1012 } 975 1013 ··· 1071 1109 guard(mutex)(&dev->lock); 1072 1110 1073 1111 if (gpio_sim_device_is_live(dev)) 1074 - return device_for_each_child(&dev->probe_data.pdev->dev, &ctx, 1112 + return device_for_each_child(&dev->pdev->dev, &ctx, 1075 1113 gpio_sim_emit_chip_name); 1076 1114 1077 1115 return sprintf(page, "none\n"); ··· 1327 1365 1328 1366 CONFIGFS_ATTR(gpio_sim_hog_config_, direction); 1329 1367 1368 + static ssize_t gpio_sim_hog_config_active_low_show(struct config_item *item, 1369 + char *page) 1370 + { 1371 + struct gpio_sim_hog *hog = to_gpio_sim_hog(item); 1372 + struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog); 1373 + 1374 + guard(mutex)(&dev->lock); 1375 + 1376 + return sprintf(page, "%c\n", hog->active_low ? '1' : '0'); 1377 + } 1378 + 1379 + static ssize_t 1380 + gpio_sim_hog_config_active_low_store(struct config_item *item, 1381 + const char *page, size_t count) 1382 + { 1383 + struct gpio_sim_hog *hog = to_gpio_sim_hog(item); 1384 + struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog); 1385 + bool active_low; 1386 + int ret; 1387 + 1388 + guard(mutex)(&dev->lock); 1389 + 1390 + if (gpio_sim_device_is_live(dev)) 1391 + return -EBUSY; 1392 + 1393 + ret = kstrtobool(page, &active_low); 1394 + if (ret) 1395 + return ret; 1396 + 1397 + hog->active_low = active_low; 1398 + 1399 + return count; 1400 + } 1401 + 1402 + CONFIGFS_ATTR(gpio_sim_hog_config_, active_low); 1403 + 1330 1404 static struct configfs_attribute *gpio_sim_hog_config_attrs[] = { 1331 1405 &gpio_sim_hog_config_attr_name, 1332 1406 &gpio_sim_hog_config_attr_direction, 1407 + &gpio_sim_hog_config_attr_active_low, 1333 1408 NULL 1334 1409 }; 1335 1410 ··· 1581 1582 dev->id = id; 1582 1583 mutex_init(&dev->lock); 1583 1584 INIT_LIST_HEAD(&dev->bank_list); 1584 - 1585 - dev_sync_probe_init(&dev->probe_data); 1586 1585 1587 1586 return &no_free_ptr(dev)->group; 1588 1587 }
+1 -1
drivers/gpio/gpio-stp-xway.c
··· 102 102 { 103 103 struct xway_stp *chip = gpiochip_get_data(gc); 104 104 105 - return (xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio)); 105 + return !!(xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio)); 106 106 } 107 107 108 108 /**
+25 -20
drivers/gpio/gpio-tegra186.c
··· 125 125 struct tegra_gpio { 126 126 struct gpio_chip gpio; 127 127 unsigned int num_irq; 128 - unsigned int *irq; 129 128 130 129 const struct tegra_gpio_soc *soc; 131 130 unsigned int num_irqs_per_bank; ··· 132 133 133 134 void __iomem *secure; 134 135 void __iomem *base; 136 + 137 + unsigned int irq[] __counted_by(num_irq); 135 138 }; 136 139 137 140 static const struct tegra_gpio_port * ··· 858 857 struct device_node *np; 859 858 struct resource *res; 860 859 char **names; 861 - int err; 860 + int node, err; 862 861 863 - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 862 + err = platform_irq_count(pdev); 863 + if (err < 0) 864 + return err; 865 + 866 + gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, irq, err), GFP_KERNEL); 864 867 if (!gpio) 865 868 return -ENOMEM; 869 + 870 + gpio->num_irq = err; 866 871 867 872 gpio->soc = device_get_match_data(&pdev->dev); 868 873 gpio->gpio.label = gpio->soc->name; ··· 896 889 if (IS_ERR(gpio->base)) 897 890 return PTR_ERR(gpio->base); 898 891 899 - err = platform_irq_count(pdev); 900 - if (err < 0) 901 - return err; 902 - 903 - gpio->num_irq = err; 904 - 905 892 err = tegra186_gpio_irqs_per_bank(gpio); 906 893 if (err < 0) 907 894 return err; 908 - 909 - gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq), 910 - GFP_KERNEL); 911 - if (!gpio->irq) 912 - return -ENOMEM; 913 895 914 896 for (i = 0; i < gpio->num_irq; i++) { 915 897 err = platform_get_irq(pdev, i); ··· 933 937 if (!names) 934 938 return -ENOMEM; 935 939 940 + node = dev_to_node(&pdev->dev); 941 + 936 942 for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) { 937 943 const struct tegra_gpio_port *port = &gpio->soc->ports[i]; 938 944 char *name; 939 945 940 946 for (j = 0; j < port->pins; j++) { 941 - if (gpio->soc->prefix) 942 - name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%s-P%s.%02x", 943 - gpio->soc->prefix, port->name, j); 947 + if (node >= 0) 948 + name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, 949 + "%d-%sP%s.%02x", node, 950 + gpio->soc->prefix ?: "", 951 + port->name, j); 944 952 else 945 - name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "P%s.%02x", 953 + name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, 954 + "%sP%s.%02x", 955 + gpio->soc->prefix ?: "", 946 956 port->name, j); 947 957 if (!name) 948 958 return -ENOMEM; ··· 1375 1373 .has_vm_support = true, 1376 1374 }; 1377 1375 1376 + /* Macro to define GPIO name prefix with separator */ 1377 + #define TEGRA_GPIO_PREFIX(_x) _x "-" 1378 + 1378 1379 #define TEGRA410_COMPUTE_GPIO_PORT(_name, _bank, _port, _pins) \ 1379 1380 TEGRA_GPIO_PORT(TEGRA410_COMPUTE, _name, _bank, _port, _pins) 1380 1381 ··· 1393 1388 .num_ports = ARRAY_SIZE(tegra410_compute_ports), 1394 1389 .ports = tegra410_compute_ports, 1395 1390 .name = "tegra410-gpio-compute", 1396 - .prefix = "COMPUTE", 1391 + .prefix = TEGRA_GPIO_PREFIX("COMPUTE"), 1397 1392 .num_irqs_per_bank = 8, 1398 1393 .instance = 0, 1399 1394 }; ··· 1423 1418 .num_ports = ARRAY_SIZE(tegra410_system_ports), 1424 1419 .ports = tegra410_system_ports, 1425 1420 .name = "tegra410-gpio-system", 1426 - .prefix = "SYSTEM", 1421 + .prefix = TEGRA_GPIO_PREFIX("SYSTEM"), 1427 1422 .num_irqs_per_bank = 8, 1428 1423 .instance = 0, 1429 1424 };
+1 -1
drivers/gpio/gpio-tps65086.c
··· 50 50 if (ret < 0) 51 51 return ret; 52 52 53 - return val & BIT(4 + offset); 53 + return !!(val & BIT(4 + offset)); 54 54 } 55 55 56 56 static int tps65086_gpio_set(struct gpio_chip *chip, unsigned int offset,
-10
drivers/gpio/gpio-ts4800.c
··· 11 11 #include <linux/platform_device.h> 12 12 #include <linux/property.h> 13 13 14 - #define DEFAULT_PIN_NUMBER 16 15 14 #define INPUT_REG_OFFSET 0x00 16 15 #define OUTPUT_REG_OFFSET 0x02 17 16 #define DIRECTION_REG_OFFSET 0x04 ··· 22 23 struct gpio_generic_chip *chip; 23 24 void __iomem *base_addr; 24 25 int retval; 25 - u32 ngpios; 26 26 27 27 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 28 28 if (!chip) ··· 30 32 base_addr = devm_platform_ioremap_resource(pdev, 0); 31 33 if (IS_ERR(base_addr)) 32 34 return PTR_ERR(base_addr); 33 - 34 - retval = device_property_read_u32(dev, "ngpios", &ngpios); 35 - if (retval == -EINVAL) 36 - ngpios = DEFAULT_PIN_NUMBER; 37 - else if (retval) 38 - return retval; 39 35 40 36 config = (struct gpio_generic_chip_config) { 41 37 .dev = dev, ··· 43 51 if (retval) 44 52 return dev_err_probe(dev, retval, 45 53 "failed to initialize the generic GPIO chip\n"); 46 - 47 - chip->gc.ngpio = ngpios; 48 54 49 55 return devm_gpiochip_add_data(dev, &chip->gc, NULL); 50 56 }
+1 -1
drivers/gpio/gpio-viperboard.c
··· 288 288 289 289 /* if io is set to output, just return the saved value */ 290 290 if (gpio->gpiob_out & (1 << offset)) 291 - return gpio->gpiob_val & (1 << offset); 291 + return !!(gpio->gpiob_val & (1 << offset)); 292 292 293 293 mutex_lock(&vb->lock); 294 294
+20 -10
drivers/gpio/gpio-virtuser.c
··· 36 36 #include <linux/string_helpers.h> 37 37 #include <linux/types.h> 38 38 39 - #include "dev-sync-probe.h" 40 - 41 39 #define GPIO_VIRTUSER_NAME_BUF_LEN 32 42 40 43 41 static DEFINE_IDA(gpio_virtuser_ida); ··· 976 978 }; 977 979 978 980 struct gpio_virtuser_device { 979 - struct dev_sync_probe_data probe_data; 981 + struct platform_device *pdev; 980 982 struct config_group group; 981 983 982 984 int id; ··· 1000 1002 { 1001 1003 lockdep_assert_held(&dev->lock); 1002 1004 1003 - return !!dev->probe_data.pdev; 1005 + return !!dev->pdev; 1004 1006 } 1005 1007 1006 1008 struct gpio_virtuser_lookup { ··· 1340 1342 1341 1343 guard(mutex)(&dev->lock); 1342 1344 1343 - pdev = dev->probe_data.pdev; 1345 + pdev = dev->pdev; 1344 1346 if (pdev) 1345 1347 return sprintf(page, "%s\n", dev_name(&pdev->dev)); 1346 1348 ··· 1448 1450 gpio_virtuser_device_activate(struct gpio_virtuser_device *dev) 1449 1451 { 1450 1452 struct platform_device_info pdevinfo; 1453 + struct platform_device *pdev; 1451 1454 struct fwnode_handle *swnode; 1452 1455 int ret; 1453 1456 ··· 1470 1471 if (ret) 1471 1472 goto err_remove_swnode; 1472 1473 1473 - ret = dev_sync_probe_register(&dev->probe_data, &pdevinfo); 1474 - if (ret) 1474 + pdev = platform_device_register_full(&pdevinfo); 1475 + if (IS_ERR(pdev)) { 1476 + ret = PTR_ERR(pdev); 1475 1477 goto err_remove_lookup_table; 1478 + } 1476 1479 1480 + wait_for_device_probe(); 1481 + if (!device_is_bound(&pdev->dev)) { 1482 + ret = -ENXIO; 1483 + goto err_unregister_pdev; 1484 + } 1485 + 1486 + dev->pdev = pdev; 1477 1487 return 0; 1478 1488 1489 + err_unregister_pdev: 1490 + platform_device_unregister(pdev); 1479 1491 err_remove_lookup_table: 1480 1492 gpio_virtuser_remove_lookup_table(dev); 1481 1493 err_remove_swnode: ··· 1502 1492 1503 1493 lockdep_assert_held(&dev->lock); 1504 1494 1505 - swnode = dev_fwnode(&dev->probe_data.pdev->dev); 1506 - dev_sync_probe_unregister(&dev->probe_data); 1495 + swnode = dev_fwnode(&dev->pdev->dev); 1496 + platform_device_unregister(dev->pdev); 1497 + dev->pdev = NULL; 1507 1498 gpio_virtuser_remove_lookup_table(dev); 1508 1499 fwnode_remove_software_node(swnode); 1509 1500 } ··· 1734 1723 &gpio_virtuser_device_config_group_type); 1735 1724 mutex_init(&dev->lock); 1736 1725 INIT_LIST_HEAD(&dev->lookup_list); 1737 - dev_sync_probe_init(&dev->probe_data); 1738 1726 1739 1727 return &no_free_ptr(dev)->group; 1740 1728 }
-70
drivers/gpio/gpiolib-acpi-core.c
··· 1220 1220 } 1221 1221 } 1222 1222 1223 - static struct gpio_desc * 1224 - acpi_gpiochip_parse_own_gpio(struct acpi_gpio_chip *achip, 1225 - struct fwnode_handle *fwnode, 1226 - const char **name, 1227 - unsigned long *lflags, 1228 - enum gpiod_flags *dflags) 1229 - { 1230 - struct gpio_chip *chip = achip->chip; 1231 - struct gpio_desc *desc; 1232 - u32 gpios[2]; 1233 - int ret; 1234 - 1235 - *lflags = GPIO_LOOKUP_FLAGS_DEFAULT; 1236 - *dflags = GPIOD_ASIS; 1237 - *name = NULL; 1238 - 1239 - ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios, 1240 - ARRAY_SIZE(gpios)); 1241 - if (ret < 0) 1242 - return ERR_PTR(ret); 1243 - 1244 - desc = gpiochip_get_desc(chip, gpios[0]); 1245 - if (IS_ERR(desc)) 1246 - return desc; 1247 - 1248 - if (gpios[1]) 1249 - *lflags |= GPIO_ACTIVE_LOW; 1250 - 1251 - if (fwnode_property_present(fwnode, "input")) 1252 - *dflags |= GPIOD_IN; 1253 - else if (fwnode_property_present(fwnode, "output-low")) 1254 - *dflags |= GPIOD_OUT_LOW; 1255 - else if (fwnode_property_present(fwnode, "output-high")) 1256 - *dflags |= GPIOD_OUT_HIGH; 1257 - else 1258 - return ERR_PTR(-EINVAL); 1259 - 1260 - fwnode_property_read_string(fwnode, "line-name", name); 1261 - 1262 - return desc; 1263 - } 1264 - 1265 - static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip) 1266 - { 1267 - struct gpio_chip *chip = achip->chip; 1268 - 1269 - device_for_each_child_node_scoped(chip->parent, fwnode) { 1270 - unsigned long lflags; 1271 - enum gpiod_flags dflags; 1272 - struct gpio_desc *desc; 1273 - const char *name; 1274 - int ret; 1275 - 1276 - if (!fwnode_property_present(fwnode, "gpio-hog")) 1277 - continue; 1278 - 1279 - desc = acpi_gpiochip_parse_own_gpio(achip, fwnode, &name, 1280 - &lflags, &dflags); 1281 - if (IS_ERR(desc)) 1282 - continue; 1283 - 1284 - ret = gpiod_hog(desc, name, lflags, dflags); 1285 - if (ret) { 1286 - dev_err(chip->parent, "Failed to hog GPIO\n"); 1287 - return; 1288 - } 1289 - } 1290 - } 1291 - 1292 1223 void acpi_gpiochip_add(struct gpio_chip *chip) 1293 1224 { 1294 1225 struct acpi_gpio_chip *acpi_gpio; ··· 1252 1321 } 1253 1322 1254 1323 acpi_gpiochip_request_regions(acpi_gpio); 1255 - acpi_gpiochip_scan_gpios(acpi_gpio); 1256 1324 acpi_dev_clear_dependencies(adev); 1257 1325 } 1258 1326
+48 -111
drivers/gpio/gpiolib-cdev.c
··· 1586 1586 #endif 1587 1587 }; 1588 1588 1589 + DEFINE_FREE(linereq_free, struct linereq *, if (!IS_ERR_OR_NULL(_T)) linereq_free(_T)) 1590 + 1589 1591 static int linereq_create(struct gpio_device *gdev, void __user *ip) 1590 1592 { 1591 1593 struct gpio_v2_line_request ulr; 1592 1594 struct gpio_v2_line_config *lc; 1593 - struct linereq *lr; 1594 - struct file *file; 1595 + struct linereq *lr __free(linereq_free) = NULL; 1595 1596 u64 flags, edflags; 1596 1597 unsigned int i; 1597 - int fd, ret; 1598 + int ret; 1598 1599 1599 1600 if (copy_from_user(&ulr, ip, sizeof(ulr))) 1600 1601 return -EFAULT; ··· 1628 1627 /* label is only initialized if consumer is set */ 1629 1628 lr->label = kstrndup(ulr.consumer, sizeof(ulr.consumer) - 1, 1630 1629 GFP_KERNEL); 1631 - if (!lr->label) { 1632 - ret = -ENOMEM; 1633 - goto out_free_linereq; 1634 - } 1630 + if (!lr->label) 1631 + return -ENOMEM; 1635 1632 } 1636 1633 1637 1634 mutex_init(&lr->config_mutex); ··· 1648 1649 u32 offset = ulr.offsets[i]; 1649 1650 struct gpio_desc *desc = gpio_device_get_desc(gdev, offset); 1650 1651 1651 - if (IS_ERR(desc)) { 1652 - ret = PTR_ERR(desc); 1653 - goto out_free_linereq; 1654 - } 1652 + if (IS_ERR(desc)) 1653 + return PTR_ERR(desc); 1655 1654 1656 1655 ret = gpiod_request_user(desc, lr->label); 1657 1656 if (ret) 1658 - goto out_free_linereq; 1657 + return ret; 1659 1658 1660 1659 lr->lines[i].desc = desc; 1661 1660 flags = gpio_v2_line_config_flags(lc, i); ··· 1661 1664 1662 1665 ret = gpiod_set_transitory(desc, false); 1663 1666 if (ret < 0) 1664 - goto out_free_linereq; 1667 + return ret; 1665 1668 1666 1669 edflags = flags & GPIO_V2_LINE_EDGE_DETECTOR_FLAGS; 1667 1670 /* ··· 1673 1676 1674 1677 ret = gpiod_direction_output_nonotify(desc, val); 1675 1678 if (ret) 1676 - goto out_free_linereq; 1679 + return ret; 1677 1680 } else if (flags & GPIO_V2_LINE_FLAG_INPUT) { 1678 1681 ret = gpiod_direction_input_nonotify(desc); 1679 1682 if (ret) 1680 - goto out_free_linereq; 1683 + return ret; 1681 1684 1682 1685 ret = edge_detector_setup(&lr->lines[i], lc, i, 1683 1686 edflags); 1684 1687 if (ret) 1685 - goto out_free_linereq; 1688 + return ret; 1686 1689 } 1687 1690 1688 1691 lr->lines[i].edflags = edflags; ··· 1697 1700 ret = blocking_notifier_chain_register(&gdev->device_notifier, 1698 1701 &lr->device_unregistered_nb); 1699 1702 if (ret) 1700 - goto out_free_linereq; 1703 + return ret; 1701 1704 1702 - fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); 1703 - if (fd < 0) { 1704 - ret = fd; 1705 - goto out_free_linereq; 1706 - } 1705 + FD_PREPARE(fdf, O_RDONLY | O_CLOEXEC, 1706 + anon_inode_getfile("gpio-line", &line_fileops, lr, 1707 + O_RDONLY | O_CLOEXEC)); 1708 + if (fdf.err) 1709 + return fdf.err; 1710 + retain_and_null_ptr(lr); 1707 1711 1708 - file = anon_inode_getfile("gpio-line", &line_fileops, lr, 1709 - O_RDONLY | O_CLOEXEC); 1710 - if (IS_ERR(file)) { 1711 - ret = PTR_ERR(file); 1712 - goto out_put_unused_fd; 1713 - } 1714 - 1715 - ulr.fd = fd; 1716 - if (copy_to_user(ip, &ulr, sizeof(ulr))) { 1717 - /* 1718 - * fput() will trigger the release() callback, so do not go onto 1719 - * the regular error cleanup path here. 1720 - */ 1721 - fput(file); 1722 - put_unused_fd(fd); 1712 + ulr.fd = fd_prepare_fd(fdf); 1713 + if (copy_to_user(ip, &ulr, sizeof(ulr))) 1723 1714 return -EFAULT; 1724 - } 1725 1715 1726 - fd_install(fd, file); 1716 + fd_publish(fdf); 1727 1717 1728 1718 dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n", 1729 - lr->num_lines); 1719 + ulr.num_lines); 1730 1720 1731 1721 return 0; 1732 - 1733 - out_put_unused_fd: 1734 - put_unused_fd(fd); 1735 - out_free_linereq: 1736 - linereq_free(lr); 1737 - return ret; 1738 1722 } 1739 1723 1740 1724 #ifdef CONFIG_GPIO_CDEV_V1 ··· 1988 2010 return IRQ_WAKE_THREAD; 1989 2011 } 1990 2012 2013 + DEFINE_FREE(lineevent_free, struct lineevent_state *, if (!IS_ERR_OR_NULL(_T)) lineevent_free(_T)) 2014 + 1991 2015 static int lineevent_create(struct gpio_device *gdev, void __user *ip) 1992 2016 { 1993 2017 struct gpioevent_request eventreq; 1994 - struct lineevent_state *le; 2018 + struct lineevent_state *le __free(lineevent_free) = NULL; 1995 2019 struct gpio_desc *desc; 1996 - struct file *file; 1997 2020 u32 offset; 1998 2021 u32 lflags; 1999 2022 u32 eflags; 2000 - int fd; 2001 2023 int ret; 2002 2024 int irq, irqflags = 0; 2003 2025 char *label; ··· 2042 2064 le->label = kstrndup(eventreq.consumer_label, 2043 2065 sizeof(eventreq.consumer_label) - 1, 2044 2066 GFP_KERNEL); 2045 - if (!le->label) { 2046 - ret = -ENOMEM; 2047 - goto out_free_le; 2048 - } 2067 + if (!le->label) 2068 + return -ENOMEM; 2049 2069 } 2050 2070 2051 2071 ret = gpiod_request_user(desc, le->label); 2052 2072 if (ret) 2053 - goto out_free_le; 2073 + return ret; 2054 2074 le->desc = desc; 2055 2075 le->eflags = eflags; 2056 2076 ··· 2056 2080 2057 2081 ret = gpiod_direction_input(desc); 2058 2082 if (ret) 2059 - goto out_free_le; 2083 + return ret; 2060 2084 2061 2085 gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); 2062 2086 2063 2087 irq = gpiod_to_irq(desc); 2064 - if (irq <= 0) { 2065 - ret = -ENODEV; 2066 - goto out_free_le; 2067 - } 2088 + if (irq <= 0) 2089 + return -ENODEV; 2068 2090 2069 2091 if (eflags & GPIOEVENT_REQUEST_RISING_EDGE) 2070 2092 irqflags |= test_bit(GPIOD_FLAG_ACTIVE_LOW, &desc->flags) ? ··· 2079 2105 ret = blocking_notifier_chain_register(&gdev->device_notifier, 2080 2106 &le->device_unregistered_nb); 2081 2107 if (ret) 2082 - goto out_free_le; 2108 + return ret; 2083 2109 2084 2110 label = make_irq_label(le->label); 2085 - if (IS_ERR(label)) { 2086 - ret = PTR_ERR(label); 2087 - goto out_free_le; 2088 - } 2111 + if (IS_ERR(label)) 2112 + return PTR_ERR(label); 2089 2113 2090 2114 /* Request a thread to read the events */ 2091 2115 ret = request_threaded_irq(irq, ··· 2094 2122 le); 2095 2123 if (ret) { 2096 2124 free_irq_label(label); 2097 - goto out_free_le; 2125 + return ret; 2098 2126 } 2099 2127 2100 2128 le->irq = irq; 2101 2129 2102 - fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); 2103 - if (fd < 0) { 2104 - ret = fd; 2105 - goto out_free_le; 2106 - } 2130 + FD_PREPARE(fdf, O_RDONLY | O_CLOEXEC, 2131 + anon_inode_getfile("gpio-event", &lineevent_fileops, le, 2132 + O_RDONLY | O_CLOEXEC)); 2133 + if (fdf.err) 2134 + return fdf.err; 2135 + retain_and_null_ptr(le); 2107 2136 2108 - file = anon_inode_getfile("gpio-event", 2109 - &lineevent_fileops, 2110 - le, 2111 - O_RDONLY | O_CLOEXEC); 2112 - if (IS_ERR(file)) { 2113 - ret = PTR_ERR(file); 2114 - goto out_put_unused_fd; 2115 - } 2116 - 2117 - eventreq.fd = fd; 2118 - if (copy_to_user(ip, &eventreq, sizeof(eventreq))) { 2119 - /* 2120 - * fput() will trigger the release() callback, so do not go onto 2121 - * the regular error cleanup path here. 2122 - */ 2123 - fput(file); 2124 - put_unused_fd(fd); 2137 + eventreq.fd = fd_prepare_fd(fdf); 2138 + if (copy_to_user(ip, &eventreq, sizeof(eventreq))) 2125 2139 return -EFAULT; 2126 - } 2127 2140 2128 - fd_install(fd, file); 2141 + fd_publish(fdf); 2129 2142 2130 2143 return 0; 2131 - 2132 - out_put_unused_fd: 2133 - put_unused_fd(fd); 2134 - out_free_le: 2135 - lineevent_free(le); 2136 - return ret; 2137 2144 } 2138 2145 2139 2146 static void gpio_v2_line_info_to_v1(struct gpio_v2_line_info *info_v2, ··· 2640 2689 struct gpio_chardev_data *cdev; 2641 2690 int ret = -ENOMEM; 2642 2691 2643 - guard(srcu)(&gdev->srcu); 2644 - 2645 - /* Fail on open if the backing gpiochip is gone */ 2646 - if (!rcu_access_pointer(gdev->chip)) 2647 - return -ENODEV; 2648 - 2649 2692 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 2650 2693 if (!cdev) 2651 2694 return -ENOMEM; ··· 2727 2782 #endif 2728 2783 }; 2729 2784 2730 - int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) 2785 + int gpiolib_cdev_register(struct gpio_chip *gc, dev_t devt) 2731 2786 { 2732 - struct gpio_chip *gc; 2787 + struct gpio_device *gdev = gc->gpiodev; 2733 2788 int ret; 2734 2789 2735 2790 cdev_init(&gdev->chrdev, &gpio_fileops); ··· 2745 2800 if (ret) { 2746 2801 destroy_workqueue(gdev->line_state_wq); 2747 2802 return ret; 2748 - } 2749 - 2750 - guard(srcu)(&gdev->srcu); 2751 - gc = srcu_dereference(gdev->chip, &gdev->srcu); 2752 - if (!gc) { 2753 - cdev_device_del(&gdev->chrdev, &gdev->dev); 2754 - destroy_workqueue(gdev->line_state_wq); 2755 - return -ENODEV; 2756 2803 } 2757 2804 2758 2805 gpiochip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
+1 -1
drivers/gpio/gpiolib-cdev.h
··· 7 7 8 8 struct gpio_device; 9 9 10 - int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt); 10 + int gpiolib_cdev_register(struct gpio_chip *gc, dev_t devt); 11 11 void gpiolib_cdev_unregister(struct gpio_device *gdev); 12 12 13 13 #endif /* GPIOLIB_CDEV_H */
+28 -155
drivers/gpio/gpiolib-of.c
··· 10 10 #include <linux/device.h> 11 11 #include <linux/err.h> 12 12 #include <linux/errno.h> 13 + #include <linux/fwnode.h> 13 14 #include <linux/io.h> 14 15 #include <linux/module.h> 15 16 #include <linux/of.h> 16 17 #include <linux/of_address.h> 17 - #include <linux/of_gpio.h> 18 18 #include <linux/pinctrl/pinctrl.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/string.h> ··· 446 446 return desc; 447 447 } 448 448 449 - /** 450 - * of_get_named_gpio() - Get a GPIO number to use with GPIO API 451 - * @np: device node to get GPIO from 452 - * @propname: Name of property containing gpio specifier(s) 453 - * @index: index of the GPIO 454 - * 455 - * **DEPRECATED** This function is deprecated and must not be used in new code. 456 - * 457 - * Returns: 458 - * GPIO number to use with Linux generic GPIO API, or one of the errno 459 - * value on the error condition. 460 - */ 461 - int of_get_named_gpio(const struct device_node *np, const char *propname, 462 - int index) 463 - { 464 - struct gpio_desc *desc; 465 - 466 - desc = of_get_named_gpiod_flags(np, propname, index, NULL); 467 - 468 - if (IS_ERR(desc)) 469 - return PTR_ERR(desc); 470 - else 471 - return desc_to_gpio(desc); 472 - } 473 - EXPORT_SYMBOL_GPL(of_get_named_gpio); 474 - 475 449 /* Converts gpio_lookup_flags into bitmask of GPIO_* values */ 476 450 static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags) 477 451 { ··· 515 541 #if IS_ENABLED(CONFIG_NFC_MRVL_UART) 516 542 { "reset", "reset-n-io", "marvell,nfc-uart" }, 517 543 { "reset", "reset-n-io", "mrvl,nfc-uart" }, 544 + #endif 545 + #if IS_ENABLED(CONFIG_NFC_S3FWRN5_I2C) 546 + { "en", "s3fwrn5,en-gpios", "samsung,s3fwrn5-i2c" }, 547 + { "wake", "s3fwrn5,fw-gpios", "samsung,s3fwrn5-i2c" }, 518 548 #endif 519 549 #if IS_ENABLED(CONFIG_PCI_LANTIQ) 520 550 /* MIPS Lantiq PCI */ ··· 713 735 return desc; 714 736 } 715 737 716 - /** 717 - * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API 718 - * @np: device node to get GPIO from 719 - * @chip: GPIO chip whose hog is parsed 720 - * @idx: Index of the GPIO to parse 721 - * @name: GPIO line name 722 - * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from 723 - * of_find_gpio() or of_parse_own_gpio() 724 - * @dflags: gpiod_flags - optional GPIO initialization flags 725 - * 726 - * Returns: 727 - * GPIO descriptor to use with Linux GPIO API, or one of the errno 728 - * value on the error condition. 729 - */ 730 - static struct gpio_desc *of_parse_own_gpio(struct device_node *np, 731 - struct gpio_chip *chip, 732 - unsigned int idx, const char **name, 733 - unsigned long *lflags, 734 - enum gpiod_flags *dflags) 738 + int of_gpiochip_get_lflags(struct gpio_chip *chip, 739 + struct fwnode_reference_args *gpiospec, 740 + unsigned long *lflags) 735 741 { 736 - struct device_node *chip_np; 737 742 enum of_gpio_flags xlate_flags; 738 - struct of_phandle_args gpiospec; 743 + struct of_phandle_args args; 739 744 struct gpio_desc *desc; 740 - unsigned int i; 741 - u32 tmp; 742 - int ret; 743 745 744 - chip_np = dev_of_node(&chip->gpiodev->dev); 745 - if (!chip_np) 746 - return ERR_PTR(-EINVAL); 746 + args.np = to_of_node(gpiospec->fwnode); 747 + args.args_count = gpiospec->nargs; 747 748 748 - xlate_flags = 0; 749 - *lflags = GPIO_LOOKUP_FLAGS_DEFAULT; 750 - *dflags = GPIOD_ASIS; 749 + for (int i = 0; i < args.args_count; i++) 750 + args.args[i] = gpiospec->args[i]; 751 751 752 - ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); 753 - if (ret) 754 - return ERR_PTR(ret); 755 - 756 - gpiospec.np = chip_np; 757 - gpiospec.args_count = tmp; 758 - 759 - for (i = 0; i < tmp; i++) { 760 - ret = of_property_read_u32_index(np, "gpios", idx * tmp + i, 761 - &gpiospec.args[i]); 762 - if (ret) 763 - return ERR_PTR(ret); 764 - } 765 - 766 - desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags); 752 + desc = of_xlate_and_get_gpiod_flags(chip, &args, &xlate_flags); 767 753 if (IS_ERR(desc)) 768 - return desc; 754 + return PTR_ERR(desc); 769 755 770 756 *lflags = of_convert_gpio_flags(xlate_flags); 771 - 772 - if (of_property_read_bool(np, "input")) 773 - *dflags |= GPIOD_IN; 774 - else if (of_property_read_bool(np, "output-low")) 775 - *dflags |= GPIOD_OUT_LOW; 776 - else if (of_property_read_bool(np, "output-high")) 777 - *dflags |= GPIOD_OUT_HIGH; 778 - else { 779 - pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n", 780 - desc_to_gpio(desc), np); 781 - return ERR_PTR(-EINVAL); 782 - } 783 - 784 - if (name && of_property_read_string(np, "line-name", name)) 785 - *name = np->name; 786 - 787 - return desc; 788 - } 789 - 790 - /** 791 - * of_gpiochip_add_hog - Add all hogs in a hog device node 792 - * @chip: gpio chip to act on 793 - * @hog: device node describing the hogs 794 - * 795 - * Returns: 796 - * 0 on success, or negative errno on failure. 797 - */ 798 - static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) 799 - { 800 - enum gpiod_flags dflags; 801 - struct gpio_desc *desc; 802 - unsigned long lflags; 803 - const char *name; 804 - unsigned int i; 805 - int ret; 806 - 807 - for (i = 0;; i++) { 808 - desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags); 809 - if (IS_ERR(desc)) 810 - break; 811 - 812 - ret = gpiod_hog(desc, name, lflags, dflags); 813 - if (ret < 0) 814 - return ret; 815 - 816 - #ifdef CONFIG_OF_DYNAMIC 817 - WRITE_ONCE(desc->hog, hog); 818 - #endif 819 - } 820 - 821 - return 0; 822 - } 823 - 824 - /** 825 - * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions 826 - * @chip: gpio chip to act on 827 - * 828 - * This is only used by of_gpiochip_add to request/set GPIO initial 829 - * configuration. 830 - * 831 - * Returns: 832 - * 0 on success, or negative errno on failure. 833 - */ 834 - static int of_gpiochip_scan_gpios(struct gpio_chip *chip) 835 - { 836 - int ret; 837 - 838 - for_each_available_child_of_node_scoped(dev_of_node(&chip->gpiodev->dev), np) { 839 - if (!of_property_read_bool(np, "gpio-hog")) 840 - continue; 841 - 842 - ret = of_gpiochip_add_hog(chip, np); 843 - if (ret < 0) 844 - return ret; 845 - 846 - of_node_set_flag(np, OF_POPULATED); 847 - } 848 757 849 758 return 0; 850 759 } ··· 787 922 if (!gdev) 788 923 return NOTIFY_DONE; /* not for us */ 789 924 790 - ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn); 925 + ret = gpiochip_add_hog(gpio_device_get_chip(gdev), of_fwnode_handle(rd->dn)); 791 926 if (ret < 0) { 792 927 pr_err("%s: failed to add hogs for %pOF\n", __func__, 793 928 rd->dn); ··· 1066 1201 1067 1202 of_node_get(np); 1068 1203 1069 - ret = of_gpiochip_scan_gpios(chip); 1070 - if (ret) 1071 - of_node_put(np); 1204 + for_each_available_child_of_node_scoped(np, child) { 1205 + if (of_property_read_bool(child, "gpio-hog")) 1206 + of_node_set_flag(child, OF_POPULATED); 1207 + } 1072 1208 1073 1209 return ret; 1074 1210 } 1075 1211 1076 1212 void of_gpiochip_remove(struct gpio_chip *chip) 1077 1213 { 1078 - of_node_put(dev_of_node(&chip->gpiodev->dev)); 1214 + struct device_node *np = dev_of_node(&chip->gpiodev->dev); 1215 + 1216 + for_each_child_of_node_scoped(np, child) { 1217 + if (of_property_present(child, "gpio-hog")) 1218 + of_node_clear_flag(child, OF_POPULATED); 1219 + } 1220 + 1221 + of_node_put(np); 1079 1222 } 1080 1223 1081 1224 bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index)
+10
drivers/gpio/gpiolib-of.h
··· 10 10 11 11 struct device_node; 12 12 struct fwnode_handle; 13 + struct fwnode_reference_args; 13 14 14 15 struct gpio_chip; 15 16 struct gpio_desc; ··· 25 24 void of_gpiochip_remove(struct gpio_chip *gc); 26 25 bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index); 27 26 int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id); 27 + int of_gpiochip_get_lflags(struct gpio_chip *chip, 28 + struct fwnode_reference_args *gpiospec, 29 + unsigned long *lflags); 28 30 #else 29 31 static inline struct gpio_desc *of_find_gpio(struct device_node *np, 30 32 const char *con_id, ··· 47 43 const char *con_id) 48 44 { 49 45 return 0; 46 + } 47 + static inline int of_gpiochip_get_lflags(struct gpio_chip *chip, 48 + struct fwnode_reference_args *gpiospec, 49 + unsigned long *lflags) 50 + { 51 + return -ENOENT; 50 52 } 51 53 #endif /* CONFIG_OF_GPIO */ 52 54
+8
drivers/gpio/gpiolib-swnode.c
··· 93 93 ret = swnode_gpio_get_reference(fwnode, propname, idx, &args); 94 94 if (ret == 0) 95 95 break; 96 + if (ret == -ENOTCONN) 97 + /* 98 + * -ENOTCONN for a software node reference lookup means 99 + * that a remote struct software_node exists but has 100 + * not yet been registered as a firmware node. Defer 101 + * until this happens. 102 + */ 103 + return ERR_PTR(-EPROBE_DEFER); 96 104 } 97 105 if (ret) { 98 106 pr_debug("%s: can't parse '%s' property of node '%pfwP[%d]'\n",
+9 -21
drivers/gpio/gpiolib-sysfs.c
··· 983 983 } 984 984 EXPORT_SYMBOL_GPL(gpiod_unexport); 985 985 986 - int gpiochip_sysfs_register(struct gpio_device *gdev) 986 + int gpiochip_sysfs_register(struct gpio_chip *gc) 987 987 { 988 + struct gpio_device *gdev = gc->gpiodev; 988 989 struct gpiodev_data *data; 989 - struct gpio_chip *chip; 990 990 struct device *parent; 991 991 int err; 992 992 ··· 999 999 if (!class_is_registered(&gpio_class)) 1000 1000 return 0; 1001 1001 1002 - guard(srcu)(&gdev->srcu); 1003 - 1004 - chip = srcu_dereference(gdev->chip, &gdev->srcu); 1005 - if (!chip) 1006 - return -ENODEV; 1007 - 1008 1002 /* 1009 1003 * For sysfs backward compatibility we need to preserve this 1010 1004 * preferred parenting to the gpio_chip parent field, if set. 1011 1005 */ 1012 - if (chip->parent) 1013 - parent = chip->parent; 1006 + if (gc->parent) 1007 + parent = gc->parent; 1014 1008 else 1015 1009 parent = &gdev->dev; 1016 1010 ··· 1023 1029 MKDEV(0, 0), data, 1024 1030 gpiochip_groups, 1025 1031 GPIOCHIP_NAME "%d", 1026 - chip->base); 1032 + gc->base); 1027 1033 if (IS_ERR(data->cdev_base)) { 1028 1034 err = PTR_ERR(data->cdev_base); 1029 1035 kfree(data); ··· 1047 1053 return 0; 1048 1054 } 1049 1055 1050 - void gpiochip_sysfs_unregister(struct gpio_device *gdev) 1056 + void gpiochip_sysfs_unregister(struct gpio_chip *gc) 1051 1057 { 1058 + struct gpio_device *gdev = gc->gpiodev; 1052 1059 struct gpiodev_data *data; 1053 1060 struct gpio_desc *desc; 1054 - struct gpio_chip *chip; 1055 1061 1056 1062 guard(mutex)(&sysfs_lock); 1057 1063 ··· 1059 1065 if (!data) 1060 1066 return; 1061 1067 1062 - guard(srcu)(&gdev->srcu); 1063 - chip = srcu_dereference(gdev->chip, &gdev->srcu); 1064 - if (!chip) 1065 - return; 1066 - 1067 1068 /* unregister gpiod class devices owned by sysfs */ 1068 - for_each_gpio_desc_with_flag(chip, desc, GPIOD_FLAG_SYSFS) { 1069 + for_each_gpio_desc_with_flag(gc, desc, GPIOD_FLAG_SYSFS) { 1069 1070 gpiod_unexport_unlocked(desc); 1070 1071 gpiod_free(desc); 1071 1072 } ··· 1079 1090 */ 1080 1091 static int gpiofind_sysfs_register(struct gpio_chip *gc, const void *data) 1081 1092 { 1082 - struct gpio_device *gdev = gc->gpiodev; 1083 1093 int ret; 1084 1094 1085 - ret = gpiochip_sysfs_register(gdev); 1095 + ret = gpiochip_sysfs_register(gc); 1086 1096 if (ret) 1087 1097 gpiochip_err(gc, "failed to register the sysfs entry: %d\n", ret); 1088 1098
+4 -4
drivers/gpio/gpiolib-sysfs.h
··· 7 7 8 8 #ifdef CONFIG_GPIO_SYSFS 9 9 10 - int gpiochip_sysfs_register(struct gpio_device *gdev); 11 - void gpiochip_sysfs_unregister(struct gpio_device *gdev); 10 + int gpiochip_sysfs_register(struct gpio_chip *gc); 11 + void gpiochip_sysfs_unregister(struct gpio_chip *gc); 12 12 13 13 #else 14 14 15 - static inline int gpiochip_sysfs_register(struct gpio_device *gdev) 15 + static inline int gpiochip_sysfs_register(struct gpio_chip *gc) 16 16 { 17 17 return 0; 18 18 } 19 19 20 - static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev) 20 + static inline void gpiochip_sysfs_unregister(struct gpio_chip *gc) 21 21 { 22 22 } 23 23
+140 -82
drivers/gpio/gpiolib.c
··· 11 11 #include <linux/errno.h> 12 12 #include <linux/file.h> 13 13 #include <linux/fs.h> 14 + #include <linux/fwnode.h> 14 15 #include <linux/idr.h> 15 16 #include <linux/interrupt.h> 16 17 #include <linux/irq.h> ··· 102 101 static DEFINE_MUTEX(gpio_devices_lock); 103 102 /* Ensures coherence during read-only accesses to the list of GPIO devices. */ 104 103 DEFINE_STATIC_SRCU(gpio_devices_srcu); 105 - 106 - static DEFINE_MUTEX(gpio_machine_hogs_mutex); 107 - static LIST_HEAD(gpio_machine_hogs); 108 104 109 105 const char *const gpio_suffixes[] = { "gpios", "gpio", NULL }; 110 106 ··· 338 340 } 339 341 EXPORT_SYMBOL_GPL(gpio_device_get_chip); 340 342 341 - /* dynamic allocation of GPIOs, e.g. on a hotplugged device */ 343 + /** 344 + * gpiochip_find_base_unlocked() - Find a global GPIO number base 345 + * @ngpio: Number of consecutive GPIOs to number 346 + * 347 + * Finds and allocates a consecutive range of unsigned integers representing 348 + * the GPIOs on the system. Using this numberspace outside of gpiolibs 349 + * internals is STRONGLY DISCOURAGED, drivers and consumers should NOT concern 350 + * themselves with this numberspace. 351 + */ 342 352 static int gpiochip_find_base_unlocked(u16 ngpio) 343 353 { 344 354 unsigned int base = GPIO_DYNAMIC_BASE; ··· 887 881 }; 888 882 889 883 #ifdef CONFIG_GPIO_CDEV 890 - #define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt)) 884 + #define gcdev_register(gc, devt) gpiolib_cdev_register((gc), (devt)) 891 885 #define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev)) 892 886 #else 893 887 /* 894 888 * gpiolib_cdev_register() indirectly calls device_add(), which is still 895 889 * required even when cdev is not selected. 896 890 */ 897 - #define gcdev_register(gdev, devt) device_add(&(gdev)->dev) 891 + #define gcdev_register(gc, devt) device_add(&(gc)->gpiodev->dev) 898 892 #define gcdev_unregister(gdev) device_del(&(gdev)->dev) 899 893 #endif 900 894 ··· 902 896 * An initial reference count has been held in gpiochip_add_data_with_key(). 903 897 * The caller should drop the reference via gpio_device_put() on errors. 904 898 */ 905 - static int gpiochip_setup_dev(struct gpio_device *gdev) 899 + static int gpiochip_setup_dev(struct gpio_chip *gc) 906 900 { 901 + struct gpio_device *gdev = gc->gpiodev; 907 902 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); 908 903 int ret; 909 904 ··· 915 908 if (fwnode && !fwnode->dev) 916 909 fwnode_dev_initialized(fwnode, false); 917 910 918 - ret = gcdev_register(gdev, gpio_devt); 911 + ret = gcdev_register(gc, gpio_devt); 919 912 if (ret) 920 913 return ret; 921 914 922 - ret = gpiochip_sysfs_register(gdev); 915 + ret = gpiochip_sysfs_register(gc); 923 916 if (ret) 924 917 goto err_remove_device; 925 918 ··· 933 926 return ret; 934 927 } 935 928 936 - static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog) 929 + int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) 937 930 { 931 + struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev); 932 + struct fwnode_reference_args gpiospec; 933 + enum gpiod_flags dflags; 934 + const char *name = NULL; 938 935 struct gpio_desc *desc; 939 - int rv; 936 + unsigned int num_hogs; 937 + unsigned long lflags; 938 + int ret, argc; 939 + /* 940 + * For devicetree-based systems, this needs to be defined in bindings 941 + * and there's no real default value. For other firmware descriptions 942 + * it makes the most sense to use 2 cells for the GPIO offset and 943 + * request flags. 944 + */ 945 + u32 cells = 2; 940 946 941 - desc = gpiochip_get_desc(gc, hog->chip_hwnum); 942 - if (IS_ERR(desc)) { 943 - gpiochip_err(gc, "%s: unable to get GPIO desc: %ld\n", 944 - __func__, PTR_ERR(desc)); 945 - return; 947 + lflags = GPIO_LOOKUP_FLAGS_DEFAULT; 948 + dflags = GPIOD_ASIS; 949 + name = NULL; 950 + 951 + argc = fwnode_property_count_u32(fwnode, "gpios"); 952 + if (argc < 0) 953 + return argc; 954 + 955 + ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells); 956 + if (ret && is_of_node(fwnode)) 957 + return ret; 958 + if (argc % cells) 959 + return -EINVAL; 960 + 961 + num_hogs = argc / cells; 962 + 963 + u32 *gpios __free(kfree) = kzalloc_objs(*gpios, argc); 964 + if (!gpios) 965 + return -ENOMEM; 966 + 967 + ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios, argc); 968 + if (ret < 0) 969 + return ret; 970 + 971 + if (fwnode_property_present(fwnode, "input")) 972 + dflags |= GPIOD_IN; 973 + else if (fwnode_property_present(fwnode, "output-low")) 974 + dflags |= GPIOD_OUT_LOW; 975 + else if (fwnode_property_present(fwnode, "output-high")) 976 + dflags |= GPIOD_OUT_HIGH; 977 + else 978 + return -EINVAL; 979 + 980 + fwnode_property_read_string(fwnode, "line-name", &name); 981 + 982 + for (unsigned int i = 0; i < num_hogs; i++) { 983 + if (is_of_node(fwnode)) { 984 + /* 985 + * OF-nodes need some additional special handling for 986 + * translating of devicetree flags. 987 + */ 988 + memset(&gpiospec, 0, sizeof(gpiospec)); 989 + gpiospec.fwnode = fwnode; 990 + gpiospec.nargs = cells; 991 + 992 + for (unsigned int j = 0; j < cells; j++) 993 + gpiospec.args[j] = gpios[i * cells + j]; 994 + 995 + ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags); 996 + if (ret) 997 + return ret; 998 + } else { 999 + /* 1000 + * GPIO_ACTIVE_LOW is currently the only lookup flag 1001 + * supported for non-OF firmware nodes. 1002 + */ 1003 + if (gpios[i * cells + 1]) 1004 + lflags |= GPIO_ACTIVE_LOW; 1005 + } 1006 + 1007 + desc = gpiochip_get_desc(gc, gpios[i * cells]); 1008 + if (IS_ERR(desc)) 1009 + return PTR_ERR(desc); 1010 + 1011 + ret = gpiod_hog(desc, name, lflags, dflags); 1012 + if (ret) 1013 + return ret; 946 1014 } 947 1015 948 - rv = gpiod_hog(desc, hog->line_name, hog->lflags, hog->dflags); 949 - if (rv) 950 - gpiod_err(desc, "%s: unable to hog GPIO line (%s:%u): %d\n", 951 - __func__, gc->label, hog->chip_hwnum, rv); 1016 + return 0; 952 1017 } 953 1018 954 - static void machine_gpiochip_add(struct gpio_chip *gc) 1019 + static int gpiochip_hog_lines(struct gpio_chip *gc) 955 1020 { 956 - struct gpiod_hog *hog; 1021 + int ret; 957 1022 958 - guard(mutex)(&gpio_machine_hogs_mutex); 1023 + device_for_each_child_node_scoped(&gc->gpiodev->dev, fwnode) { 1024 + if (!fwnode_property_present(fwnode, "gpio-hog")) 1025 + continue; 959 1026 960 - list_for_each_entry(hog, &gpio_machine_hogs, list) { 961 - if (!strcmp(gc->label, hog->chip_label)) 962 - gpiochip_machine_hog(gc, hog); 1027 + ret = gpiochip_add_hog(gc, fwnode); 1028 + if (ret) 1029 + return ret; 963 1030 } 1031 + 1032 + return 0; 964 1033 } 965 1034 966 1035 static void gpiochip_setup_devs(void) 967 1036 { 968 1037 struct gpio_device *gdev; 1038 + struct gpio_chip *gc; 969 1039 int ret; 970 1040 971 1041 guard(srcu)(&gpio_devices_srcu); 972 1042 973 1043 list_for_each_entry_srcu(gdev, &gpio_devices, list, 974 1044 srcu_read_lock_held(&gpio_devices_srcu)) { 975 - ret = gpiochip_setup_dev(gdev); 1045 + guard(srcu)(&gdev->srcu); 1046 + 1047 + gc = srcu_dereference(gdev->chip, &gdev->srcu); 1048 + if (!gc) { 1049 + dev_err(&gdev->dev, "Underlying GPIO chip is gone\n"); 1050 + continue; 1051 + } 1052 + 1053 + ret = gpiochip_setup_dev(gc); 976 1054 if (ret) { 977 1055 gpio_device_put(gdev); 978 1056 dev_err(&gdev->dev, ··· 1289 1197 1290 1198 acpi_gpiochip_add(gc); 1291 1199 1292 - machine_gpiochip_add(gc); 1200 + ret = gpiochip_hog_lines(gc); 1201 + if (ret) 1202 + goto err_remove_of_chip; 1293 1203 1294 1204 ret = gpiochip_irqchip_init_valid_mask(gc); 1295 1205 if (ret) ··· 1318 1224 * Otherwise, defer until later. 1319 1225 */ 1320 1226 if (gpiolib_initialized) { 1321 - ret = gpiochip_setup_dev(gdev); 1227 + ret = gpiochip_setup_dev(gc); 1322 1228 if (ret) 1323 1229 goto err_teardown_shared; 1324 1230 } ··· 1378 1284 struct gpio_device *gdev = gc->gpiodev; 1379 1285 1380 1286 /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ 1381 - gpiochip_sysfs_unregister(gdev); 1287 + gpiochip_sysfs_unregister(gc); 1382 1288 gpiochip_free_hogs(gc); 1383 1289 gpiochip_free_remaining_irqs(gc); 1384 1290 ··· 1483 1389 1484 1390 static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, const void *fwnode) 1485 1391 { 1486 - return device_match_fwnode(&gc->gpiodev->dev, fwnode); 1392 + struct device *dev = &gc->gpiodev->dev; 1393 + struct fwnode_handle *node = dev_fwnode(dev); 1394 + 1395 + if (IS_ERR(fwnode)) 1396 + return 0; 1397 + 1398 + if (device_match_fwnode(dev, fwnode)) 1399 + return 1; 1400 + 1401 + return node && node->secondary == fwnode; 1487 1402 } 1488 1403 1489 1404 /** ··· 4572 4469 } 4573 4470 EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table); 4574 4471 4575 - /** 4576 - * gpiod_add_hogs() - register a set of GPIO hogs from machine code 4577 - * @hogs: table of gpio hog entries with a zeroed sentinel at the end 4578 - */ 4579 - void gpiod_add_hogs(struct gpiod_hog *hogs) 4580 - { 4581 - struct gpiod_hog *hog; 4582 - 4583 - guard(mutex)(&gpio_machine_hogs_mutex); 4584 - 4585 - for (hog = &hogs[0]; hog->chip_label; hog++) { 4586 - list_add_tail(&hog->list, &gpio_machine_hogs); 4587 - 4588 - /* 4589 - * The chip may have been registered earlier, so check if it 4590 - * exists and, if so, try to hog the line now. 4591 - */ 4592 - struct gpio_device *gdev __free(gpio_device_put) = 4593 - gpio_device_find_by_label(hog->chip_label); 4594 - if (gdev) 4595 - gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); 4596 - } 4597 - } 4598 - EXPORT_SYMBOL_GPL(gpiod_add_hogs); 4599 - 4600 - void gpiod_remove_hogs(struct gpiod_hog *hogs) 4601 - { 4602 - struct gpiod_hog *hog; 4603 - 4604 - guard(mutex)(&gpio_machine_hogs_mutex); 4605 - 4606 - for (hog = &hogs[0]; hog->chip_label; hog++) 4607 - list_del(&hog->list); 4608 - } 4609 - EXPORT_SYMBOL_GPL(gpiod_remove_hogs); 4610 - 4611 4472 static bool gpiod_match_lookup_table(struct device *dev, 4612 4473 const struct gpiod_lookup_table *table) 4613 4474 { ··· 4624 4557 return desc; 4625 4558 } 4626 4559 4627 - dev_warn(dev, "cannot find GPIO line %s, deferring\n", 4628 - p->key); 4560 + dev_dbg(dev, "cannot find GPIO line %s, deferring\n", 4561 + p->key); 4629 4562 return ERR_PTR(-EPROBE_DEFER); 4630 4563 } 4631 4564 ··· 4639 4572 * consumer be probed again or let the Deferred 4640 4573 * Probe infrastructure handle the error. 4641 4574 */ 4642 - dev_warn(dev, "cannot find GPIO chip %s, deferring\n", 4643 - p->key); 4575 + dev_dbg(dev, "cannot find GPIO chip %s, deferring\n", 4576 + p->key); 4644 4577 return ERR_PTR(-EPROBE_DEFER); 4645 4578 } 4646 4579 ··· 5384 5317 5385 5318 #ifdef CONFIG_DEBUG_FS 5386 5319 5387 - static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) 5320 + static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *gc) 5388 5321 { 5389 5322 bool active_low, is_irq, is_out; 5390 5323 struct gpio_desc *desc; 5391 5324 unsigned int gpio = 0; 5392 - struct gpio_chip *gc; 5393 5325 unsigned long flags; 5394 5326 int value; 5395 - 5396 - guard(srcu)(&gdev->srcu); 5397 - 5398 - gc = srcu_dereference(gdev->chip, &gdev->srcu); 5399 - if (!gc) { 5400 - seq_puts(s, "Underlying GPIO chip is gone\n"); 5401 - return; 5402 - } 5403 5327 5404 5328 for_each_gpio_desc(gc, desc) { 5405 5329 guard(srcu)(&desc->gdev->desc_srcu); ··· 5504 5446 if (gc->dbg_show) 5505 5447 gc->dbg_show(s, gc); 5506 5448 else 5507 - gpiolib_dbg_show(s, gdev); 5449 + gpiolib_dbg_show(s, gc); 5508 5450 5509 5451 return 0; 5510 5452 }
+5 -1
drivers/gpio/gpiolib.h
··· 17 17 #include <linux/module.h> 18 18 #include <linux/notifier.h> 19 19 #include <linux/spinlock.h> 20 + #include <linux/string.h> 20 21 #include <linux/srcu.h> 21 22 #include <linux/workqueue.h> 22 23 23 24 #define GPIOCHIP_NAME "gpiochip" 25 + 26 + struct fwnode_handle; 24 27 25 28 /** 26 29 * struct gpio_device - internal state container for GPIO devices ··· 110 107 if (con_id) \ 111 108 snprintf(propname, sizeof(propname), "%s-%s", con_id, __gs); \ 112 109 else \ 113 - snprintf(propname, sizeof(propname), "%s", __gs); \ 110 + strscpy(propname, __gs); \ 114 111 1; \ 115 112 }); \ 116 113 __suffixes++) ··· 276 273 int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce); 277 274 int gpiod_hog(struct gpio_desc *desc, const char *name, 278 275 unsigned long lflags, enum gpiod_flags dflags); 276 + int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode); 279 277 int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev); 280 278 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); 281 279 const char *gpiod_get_label(struct gpio_desc *desc);
+16 -31
drivers/nfc/nfcmrvl/main.c
··· 6 6 */ 7 7 8 8 #include <linux/module.h> 9 - #include <linux/gpio.h> 9 + #include <linux/gpio/consumer.h> 10 10 #include <linux/delay.h> 11 - #include <linux/of_gpio.h> 11 + #include <linux/of.h> 12 12 #include <linux/nfc.h> 13 13 #include <net/nfc/nci.h> 14 14 #include <net/nfc/nci_core.h> ··· 112 112 113 113 memcpy(&priv->config, pdata, sizeof(*pdata)); 114 114 115 - if (gpio_is_valid(priv->config.reset_n_io)) { 116 - rc = gpio_request_one(priv->config.reset_n_io, 117 - GPIOF_OUT_INIT_LOW, 118 - "nfcmrvl_reset_n"); 119 - if (rc < 0) { 120 - priv->config.reset_n_io = -EINVAL; 121 - nfc_err(dev, "failed to request reset_n io\n"); 115 + if (!priv->config.reset_gpio) { 116 + priv->config.reset_gpio = 117 + devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 118 + if (IS_ERR(priv->config.reset_gpio)) { 119 + priv->config.reset_gpio = NULL; 120 + nfc_err(dev, "failed to get reset gpio\n"); 122 121 } 123 122 } 124 123 ··· 143 144 if (!priv->ndev) { 144 145 nfc_err(dev, "nci_allocate_device failed\n"); 145 146 rc = -ENOMEM; 146 - goto error_free_gpio; 147 + goto error_free; 147 148 } 148 149 149 150 rc = nfcmrvl_fw_dnld_init(priv); ··· 170 171 nfcmrvl_fw_dnld_deinit(priv); 171 172 error_free_dev: 172 173 nci_free_device(priv->ndev); 173 - error_free_gpio: 174 - if (gpio_is_valid(priv->config.reset_n_io)) 175 - gpio_free(priv->config.reset_n_io); 174 + error_free: 176 175 kfree(priv); 177 176 return ERR_PTR(rc); 178 177 } ··· 185 188 nfcmrvl_fw_dnld_abort(priv); 186 189 187 190 nfcmrvl_fw_dnld_deinit(priv); 188 - 189 - if (gpio_is_valid(priv->config.reset_n_io)) 190 - gpio_free(priv->config.reset_n_io); 191 191 192 192 nci_free_device(ndev); 193 193 kfree(priv); ··· 227 233 /* Reset possible fault of previous session */ 228 234 clear_bit(NFCMRVL_PHY_ERROR, &priv->flags); 229 235 230 - if (gpio_is_valid(priv->config.reset_n_io)) { 236 + if (priv->config.reset_gpio) { 231 237 nfc_info(priv->dev, "reset the chip\n"); 232 - gpio_set_value(priv->config.reset_n_io, 0); 238 + gpiod_set_value(priv->config.reset_gpio, 1); 233 239 usleep_range(5000, 10000); 234 - gpio_set_value(priv->config.reset_n_io, 1); 240 + gpiod_set_value(priv->config.reset_gpio, 0); 235 241 } else 236 242 nfc_info(priv->dev, "no reset available on this interface\n"); 237 243 } 238 244 239 245 void nfcmrvl_chip_halt(struct nfcmrvl_private *priv) 240 246 { 241 - if (gpio_is_valid(priv->config.reset_n_io)) 242 - gpio_set_value(priv->config.reset_n_io, 0); 247 + if (priv->config.reset_gpio) 248 + gpiod_set_value(priv->config.reset_gpio, 1); 243 249 } 244 250 245 251 int nfcmrvl_parse_dt(struct device_node *node, 246 252 struct nfcmrvl_platform_data *pdata) 247 253 { 248 - int reset_n_io; 249 - 250 - reset_n_io = of_get_named_gpio(node, "reset-n-io", 0); 251 - if (reset_n_io < 0) { 252 - pr_info("no reset-n-io config\n"); 253 - } else if (!gpio_is_valid(reset_n_io)) { 254 - pr_err("invalid reset-n-io GPIO\n"); 255 - return reset_n_io; 256 - } 257 - pdata->reset_n_io = reset_n_io; 254 + pdata->reset_gpio = NULL; 258 255 pdata->hci_muxed = of_property_read_bool(node, "hci-muxed"); 259 256 260 257 return 0;
+3 -1
drivers/nfc/nfcmrvl/nfcmrvl.h
··· 10 10 11 11 #include "fw_dnld.h" 12 12 13 + struct gpio_desc; 14 + 13 15 /* Define private flags: */ 14 16 #define NFCMRVL_NCI_RUNNING 1 15 17 #define NFCMRVL_PHY_ERROR 2 ··· 56 54 */ 57 55 58 56 /* GPIO that is wired to RESET_N signal */ 59 - int reset_n_io; 57 + struct gpio_desc *reset_gpio; 60 58 /* Tell if transport is muxed in HCI one */ 61 59 bool hci_muxed; 62 60
+16 -7
drivers/nfc/nfcmrvl/uart.c
··· 8 8 #include <linux/delay.h> 9 9 #include <linux/device.h> 10 10 #include <linux/err.h> 11 + #include <linux/gpio/consumer.h> 11 12 #include <linux/module.h> 12 13 #include <linux/of.h> 13 14 #include <linux/printk.h> ··· 21 20 static unsigned int hci_muxed; 22 21 static unsigned int flow_control; 23 22 static unsigned int break_control; 24 - static int reset_n_io = -EINVAL; 25 23 26 24 /* 27 25 * NFCMRVL NCI OPS ··· 62 62 }; 63 63 64 64 static int nfcmrvl_uart_parse_dt(struct device_node *node, 65 - struct nfcmrvl_platform_data *pdata) 65 + struct nfcmrvl_platform_data *pdata, 66 + struct device *dev) 66 67 { 67 68 struct device_node *matched_node; 69 + struct gpio_desc *reset_gpio; 68 70 int ret; 69 71 70 72 matched_node = of_get_compatible_child(node, "marvell,nfc-uart"); ··· 85 83 86 84 pdata->flow_control = of_property_read_bool(matched_node, "flow-control"); 87 85 pdata->break_control = of_property_read_bool(matched_node, "break-control"); 86 + 87 + reset_gpio = devm_fwnode_gpiod_get_optional(dev, 88 + of_fwnode_handle(matched_node), 89 + "reset", GPIOD_OUT_HIGH, 90 + "nfcmrvl_reset_n"); 91 + if (IS_ERR(reset_gpio)) { 92 + of_node_put(matched_node); 93 + return PTR_ERR(reset_gpio); 94 + } 95 + pdata->reset_gpio = reset_gpio; 88 96 89 97 of_node_put(matched_node); 90 98 ··· 119 107 */ 120 108 121 109 if (dev && dev->parent && dev->parent->of_node) 122 - if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0) 110 + if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0) 123 111 pdata = &config; 124 112 125 113 if (!pdata) { 126 114 pr_info("No platform data / DT -> fallback to module params\n"); 127 115 config.hci_muxed = hci_muxed; 128 - config.reset_n_io = reset_n_io; 116 + config.reset_gpio = NULL; 129 117 config.flow_control = flow_control; 130 118 config.break_control = break_control; 131 119 pdata = &config; ··· 213 201 214 202 module_param(hci_muxed, uint, 0); 215 203 MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one."); 216 - 217 - module_param(reset_n_io, int, 0); 218 - MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");
+1 -1
drivers/nfc/nfcmrvl/usb.c
··· 294 294 295 295 /* No configuration for USB */ 296 296 memset(&config, 0, sizeof(config)); 297 - config.reset_n_io = -EINVAL; 297 + config.reset_gpio = NULL; 298 298 299 299 nfc_info(&udev->dev, "intf %p id %p\n", intf, id); 300 300
+7 -47
drivers/nfc/s3fwrn5/i2c.c
··· 8 8 9 9 #include <linux/clk.h> 10 10 #include <linux/i2c.h> 11 - #include <linux/gpio.h> 11 + #include <linux/gpio/consumer.h> 12 12 #include <linux/delay.h> 13 - #include <linux/of_gpio.h> 14 - #include <linux/of_irq.h> 15 13 #include <linux/module.h> 16 14 17 15 #include <net/nfc/nfc.h> ··· 144 146 return IRQ_HANDLED; 145 147 } 146 148 147 - static int s3fwrn5_i2c_parse_dt(struct i2c_client *client) 148 - { 149 - struct s3fwrn5_i2c_phy *phy = i2c_get_clientdata(client); 150 - struct device_node *np = client->dev.of_node; 151 - 152 - if (!np) 153 - return -ENODEV; 154 - 155 - phy->common.gpio_en = of_get_named_gpio(np, "en-gpios", 0); 156 - if (!gpio_is_valid(phy->common.gpio_en)) { 157 - /* Support also deprecated property */ 158 - phy->common.gpio_en = of_get_named_gpio(np, 159 - "s3fwrn5,en-gpios", 160 - 0); 161 - if (!gpio_is_valid(phy->common.gpio_en)) 162 - return -ENODEV; 163 - } 164 - 165 - phy->common.gpio_fw_wake = of_get_named_gpio(np, "wake-gpios", 0); 166 - if (!gpio_is_valid(phy->common.gpio_fw_wake)) { 167 - /* Support also deprecated property */ 168 - phy->common.gpio_fw_wake = of_get_named_gpio(np, 169 - "s3fwrn5,fw-gpios", 170 - 0); 171 - if (!gpio_is_valid(phy->common.gpio_fw_wake)) 172 - return -ENODEV; 173 - } 174 - 175 - return 0; 176 - } 177 - 178 149 static int s3fwrn5_i2c_probe(struct i2c_client *client) 179 150 { 180 151 struct s3fwrn5_i2c_phy *phy; ··· 160 193 phy->i2c_dev = client; 161 194 i2c_set_clientdata(client, phy); 162 195 163 - ret = s3fwrn5_i2c_parse_dt(client); 164 - if (ret < 0) 165 - return ret; 196 + phy->common.gpio_en = devm_gpiod_get(&client->dev, "en", GPIOD_OUT_HIGH); 197 + if (IS_ERR(phy->common.gpio_en)) 198 + return PTR_ERR(phy->common.gpio_en); 166 199 167 - ret = devm_gpio_request_one(&phy->i2c_dev->dev, phy->common.gpio_en, 168 - GPIOF_OUT_INIT_HIGH, "s3fwrn5_en"); 169 - if (ret < 0) 170 - return ret; 171 - 172 - ret = devm_gpio_request_one(&phy->i2c_dev->dev, 173 - phy->common.gpio_fw_wake, 174 - GPIOF_OUT_INIT_LOW, "s3fwrn5_fw_wake"); 175 - if (ret < 0) 176 - return ret; 200 + phy->common.gpio_fw_wake = devm_gpiod_get(&client->dev, "wake", GPIOD_OUT_LOW); 201 + if (IS_ERR(phy->common.gpio_fw_wake)) 202 + return PTR_ERR(phy->common.gpio_fw_wake); 177 203 178 204 /* 179 205 * S3FWRN5 depends on a clock input ("XI" pin) to function properly.
+5 -6
drivers/nfc/s3fwrn5/phy_common.c
··· 8 8 * Bongsu Jeon <bongsu.jeon@samsung.com> 9 9 */ 10 10 11 - #include <linux/gpio.h> 12 11 #include <linux/delay.h> 13 12 #include <linux/module.h> 14 13 ··· 18 19 struct phy_common *phy = phy_id; 19 20 20 21 mutex_lock(&phy->mutex); 21 - gpio_set_value(phy->gpio_fw_wake, wake); 22 + gpiod_set_value(phy->gpio_fw_wake, wake); 22 23 if (wake) 23 24 msleep(S3FWRN5_EN_WAIT_TIME); 24 25 mutex_unlock(&phy->mutex); ··· 32 33 33 34 phy->mode = mode; 34 35 35 - gpio_set_value(phy->gpio_en, 1); 36 - gpio_set_value(phy->gpio_fw_wake, 0); 36 + gpiod_set_value(phy->gpio_en, 1); 37 + gpiod_set_value(phy->gpio_fw_wake, 0); 37 38 if (mode == S3FWRN5_MODE_FW) 38 - gpio_set_value(phy->gpio_fw_wake, 1); 39 + gpiod_set_value(phy->gpio_fw_wake, 1); 39 40 40 41 if (mode != S3FWRN5_MODE_COLD) { 41 42 msleep(S3FWRN5_EN_WAIT_TIME); 42 - gpio_set_value(phy->gpio_en, 0); 43 + gpiod_set_value(phy->gpio_en, 0); 43 44 msleep(S3FWRN5_EN_WAIT_TIME); 44 45 } 45 46
+3 -2
drivers/nfc/s3fwrn5/phy_common.h
··· 12 12 #define __NFC_S3FWRN5_PHY_COMMON_H 13 13 14 14 #include <linux/mutex.h> 15 + #include <linux/gpio/consumer.h> 15 16 #include <net/nfc/nci_core.h> 16 17 17 18 #include "s3fwrn5.h" ··· 22 21 struct phy_common { 23 22 struct nci_dev *ndev; 24 23 25 - int gpio_en; 26 - int gpio_fw_wake; 24 + struct gpio_desc *gpio_en; 25 + struct gpio_desc *gpio_fw_wake; 27 26 28 27 struct mutex mutex; 29 28
+10 -33
drivers/nfc/s3fwrn5/uart.c
··· 10 10 11 11 #include <linux/device.h> 12 12 #include <linux/kernel.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/module.h> 14 15 #include <linux/nfc.h> 15 16 #include <linux/netdevice.h> 16 - #include <linux/of.h> 17 17 #include <linux/serdev.h> 18 - #include <linux/gpio.h> 19 - #include <linux/of_gpio.h> 18 + #include <linux/gpio/consumer.h> 20 19 21 20 #include "phy_common.h" 22 21 ··· 91 92 }; 92 93 MODULE_DEVICE_TABLE(of, s3fwrn82_uart_of_match); 93 94 94 - static int s3fwrn82_uart_parse_dt(struct serdev_device *serdev) 95 - { 96 - struct s3fwrn82_uart_phy *phy = serdev_device_get_drvdata(serdev); 97 - struct device_node *np = serdev->dev.of_node; 98 - 99 - if (!np) 100 - return -ENODEV; 101 - 102 - phy->common.gpio_en = of_get_named_gpio(np, "en-gpios", 0); 103 - if (!gpio_is_valid(phy->common.gpio_en)) 104 - return -ENODEV; 105 - 106 - phy->common.gpio_fw_wake = of_get_named_gpio(np, "wake-gpios", 0); 107 - if (!gpio_is_valid(phy->common.gpio_fw_wake)) 108 - return -ENODEV; 109 - 110 - return 0; 111 - } 112 - 113 95 static int s3fwrn82_uart_probe(struct serdev_device *serdev) 114 96 { 115 97 struct s3fwrn82_uart_phy *phy; ··· 124 144 125 145 serdev_device_set_flow_control(serdev, false); 126 146 127 - ret = s3fwrn82_uart_parse_dt(serdev); 128 - if (ret < 0) 147 + phy->common.gpio_en = devm_gpiod_get(&serdev->dev, "en", GPIOD_OUT_HIGH); 148 + if (IS_ERR(phy->common.gpio_en)) { 149 + ret = PTR_ERR(phy->common.gpio_en); 129 150 goto err_serdev; 151 + } 130 152 131 - ret = devm_gpio_request_one(&phy->ser_dev->dev, phy->common.gpio_en, 132 - GPIOF_OUT_INIT_HIGH, "s3fwrn82_en"); 133 - if (ret < 0) 153 + phy->common.gpio_fw_wake = devm_gpiod_get(&serdev->dev, "wake", GPIOD_OUT_LOW); 154 + if (IS_ERR(phy->common.gpio_fw_wake)) { 155 + ret = PTR_ERR(phy->common.gpio_fw_wake); 134 156 goto err_serdev; 135 - 136 - ret = devm_gpio_request_one(&phy->ser_dev->dev, 137 - phy->common.gpio_fw_wake, 138 - GPIOF_OUT_INIT_LOW, "s3fwrn82_fw_wake"); 139 - if (ret < 0) 140 - goto err_serdev; 157 + } 141 158 142 159 ret = s3fwrn5_probe(&phy->common.ndev, phy, &phy->ser_dev->dev, 143 160 &uart_phy_ops);
+31
drivers/pinctrl/core.c
··· 30 30 #include <linux/pinctrl/consumer.h> 31 31 #include <linux/pinctrl/devinfo.h> 32 32 #include <linux/pinctrl/machine.h> 33 + #include <linux/pinctrl/pinconf.h> 33 34 #include <linux/pinctrl/pinctrl.h> 34 35 35 36 #include "core.h" ··· 938 937 return ret; 939 938 } 940 939 EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config); 940 + 941 + /** 942 + * pinctrl_gpio_get_config() - Get the config for a given GPIO pin 943 + * @gc: GPIO chip structure from the GPIO subsystem 944 + * @offset: hardware offset of the GPIO relative to the controller 945 + * @config: the configuration to query. On success it holds the result 946 + * Return: 0 on success, negative errno otherwise 947 + */ 948 + int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset, unsigned long *config) 949 + { 950 + struct pinctrl_gpio_range *range; 951 + struct pinctrl_dev *pctldev; 952 + int ret, pin; 953 + 954 + ret = pinctrl_get_device_gpio_range(gc, offset, &pctldev, &range); 955 + if (ret) 956 + return ret; 957 + 958 + mutex_lock(&pctldev->mutex); 959 + pin = gpio_to_pin(range, gc, offset); 960 + ret = pin_config_get_for_pin(pctldev, pin, config); 961 + mutex_unlock(&pctldev->mutex); 962 + 963 + if (ret) 964 + return ret; 965 + 966 + *config = pinconf_to_config_argument(*config); 967 + return 0; 968 + } 969 + EXPORT_SYMBOL_GPL(pinctrl_gpio_get_config); 941 970 942 971 static struct pinctrl_state *find_state(struct pinctrl *p, 943 972 const char *name)
+6
drivers/pinctrl/pinconf.h
··· 74 74 return -ENOTSUPP; 75 75 } 76 76 77 + static inline int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned int pin, 78 + unsigned long *config) 79 + { 80 + return -ENOTSUPP; 81 + } 82 + 77 83 #endif 78 84 79 85 #if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)
+33 -13
drivers/pinctrl/pinctrl-scmi.c
··· 251 251 case PIN_CONFIG_MODE_LOW_POWER: 252 252 *type = SCMI_PIN_LOW_POWER_MODE; 253 253 break; 254 - case PIN_CONFIG_LEVEL: 255 - *type = SCMI_PIN_OUTPUT_VALUE; 256 - break; 257 254 case PIN_CONFIG_OUTPUT_ENABLE: 258 255 *type = SCMI_PIN_OUTPUT_MODE; 259 - break; 260 - case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: 261 - *type = SCMI_PIN_OUTPUT_VALUE; 262 256 break; 263 257 case PIN_CONFIG_POWER_SOURCE: 264 258 *type = SCMI_PIN_POWER_SOURCE; ··· 270 276 return 0; 271 277 } 272 278 279 + static int pinctrl_scmi_map_pinconf_type_get(enum pin_config_param param, 280 + enum scmi_pinctrl_conf_type *type) 281 + { 282 + if (param == PIN_CONFIG_LEVEL) { 283 + *type = SCMI_PIN_INPUT_VALUE; 284 + return 0; 285 + } 286 + 287 + return pinctrl_scmi_map_pinconf_type(param, type); 288 + } 289 + 290 + static int pinctrl_scmi_map_pinconf_type_set(enum pin_config_param param, 291 + enum scmi_pinctrl_conf_type *type) 292 + { 293 + if (param == PIN_CONFIG_LEVEL) { 294 + *type = SCMI_PIN_OUTPUT_VALUE; 295 + return 0; 296 + } 297 + 298 + return pinctrl_scmi_map_pinconf_type(param, type); 299 + } 300 + 273 301 static int pinctrl_scmi_pinconf_get(struct pinctrl_dev *pctldev, 274 302 unsigned int pin, unsigned long *config) 275 303 { ··· 306 290 307 291 config_type = pinconf_to_config_param(*config); 308 292 309 - ret = pinctrl_scmi_map_pinconf_type(config_type, &type); 293 + ret = pinctrl_scmi_map_pinconf_type_get(config_type, &type); 310 294 if (ret) 311 295 return ret; 312 296 ··· 361 345 unsigned long *configs, 362 346 unsigned int num_configs) 363 347 { 364 - int i, ret; 348 + int i, cnt, ret; 365 349 struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); 366 350 enum scmi_pinctrl_conf_type config_type[SCMI_NUM_CONFIGS]; 367 351 u32 config_value[SCMI_NUM_CONFIGS]; ··· 377 361 if (ret) 378 362 return ret; 379 363 364 + cnt = 0; 380 365 for (i = 0; i < num_configs; i++) { 381 366 param = pinconf_to_config_param(configs[i]); 382 - ret = pinctrl_scmi_map_pinconf_type(param, &p_config_type[i]); 367 + if (param == PIN_CONFIG_PERSIST_STATE) 368 + continue; 369 + ret = pinctrl_scmi_map_pinconf_type_set(param, &p_config_type[cnt]); 383 370 if (ret) { 384 371 dev_err(pmx->dev, "Error map pinconf_type %d\n", ret); 385 372 goto free_config; 386 373 } 387 - p_config_value[i] = pinconf_to_config_argument(configs[i]); 374 + p_config_value[cnt] = pinconf_to_config_argument(configs[i]); 375 + cnt++; 388 376 } 389 377 390 - ret = pinctrl_ops->settings_conf(pmx->ph, pin, PIN_TYPE, num_configs, 378 + ret = pinctrl_ops->settings_conf(pmx->ph, pin, PIN_TYPE, cnt, 391 379 p_config_type, p_config_value); 392 380 if (ret) 393 381 dev_err(pmx->dev, "Error parsing config %d\n", ret); ··· 425 405 426 406 for (i = 0; i < num_configs; i++) { 427 407 param = pinconf_to_config_param(configs[i]); 428 - ret = pinctrl_scmi_map_pinconf_type(param, &p_config_type[i]); 408 + ret = pinctrl_scmi_map_pinconf_type_set(param, &p_config_type[i]); 429 409 if (ret) { 430 410 dev_err(pmx->dev, "Error map pinconf_type %d\n", ret); 431 411 goto free_config; ··· 460 440 return -EINVAL; 461 441 462 442 config_type = pinconf_to_config_param(*config); 463 - ret = pinctrl_scmi_map_pinconf_type(config_type, &type); 443 + ret = pinctrl_scmi_map_pinconf_type_get(config_type, &type); 464 444 if (ret) { 465 445 dev_err(pmx->dev, "Error map pinconf_type %d\n", ret); 466 446 return ret;
-2
drivers/regulator/Kconfig
··· 1232 1232 depends on ARM || ARM64 || COMPILE_TEST 1233 1233 depends on BACKLIGHT_CLASS_DEVICE 1234 1234 depends on I2C 1235 - depends on OF_GPIO 1236 1235 select REGMAP_I2C 1237 1236 help 1238 1237 This driver supports ATTINY regulator on the Raspberry Pi 7-inch ··· 1331 1332 depends on I2C && GPIOLIB && OF 1332 1333 select REGMAP 1333 1334 select CRC8 1334 - select OF_GPIO 1335 1335 help 1336 1336 This driver adds support for RT5133 PMIC regulators. 1337 1337 RT5133 is an integrated chip. It includes 8 LDOs and 3 GPOs that
+2
include/linux/gpio/consumer.h
··· 6 6 #include <linux/err.h> 7 7 #include <linux/types.h> 8 8 9 + #include "defs.h" 10 + 9 11 struct acpi_device; 10 12 struct device; 11 13 struct fwnode_handle;
+9
include/linux/gpio/defs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __LINUX_GPIO_DEFS_H 4 + #define __LINUX_GPIO_DEFS_H 5 + 6 + #define GPIO_LINE_DIRECTION_IN 1 7 + #define GPIO_LINE_DIRECTION_OUT 0 8 + 9 + #endif /* __LINUX_GPIO_DEFS_H */
+10 -5
include/linux/gpio/driver.h
··· 20 20 #include <asm/msi.h> 21 21 #endif 22 22 23 + #include "defs.h" 24 + 23 25 struct device; 24 26 struct irq_chip; 25 27 struct irq_data; ··· 43 41 msi_alloc_info_t msiinfo; 44 42 #endif 45 43 }; 46 - 47 - #define GPIO_LINE_DIRECTION_IN 1 48 - #define GPIO_LINE_DIRECTION_OUT 0 49 44 50 45 /** 51 46 * struct gpio_irq_chip - GPIO interrupt controller ··· 343 344 * @direction_output: configures signal "offset" as output, returns 0 on 344 345 * success or a negative error number. This can be omitted on input-only 345 346 * or output-only gpio chips. 346 - * @get: returns value for signal "offset", 0=low, 1=high, or negative error 347 + * @get: returns value for signal "offset", 0=low, 1=high, or negative error. 348 + * the low and high values are defined as physical low on the line 349 + * in/out to the connector such as a physical pad, pin or rail. The GPIO 350 + * library has internal logic to handle lines that are active low, such 351 + * as indicated by overstrike or #name in a schematic, and the driver 352 + * should not try to second-guess the logic value of a line. 347 353 * @get_multiple: reads values for multiple signals defined by "mask" and 348 354 * stores them in "bits", returns 0 on success or negative error 349 355 * @set: assigns output value for signal "offset", returns 0 on success or 350 - * negative error value 356 + * negative error value. The output value follows the same semantic 357 + * rules as for @get. 351 358 * @set_multiple: assigns output values for multiple signals defined by 352 359 * "mask", returns 0 on success or negative error value 353 360 * @set_config: optional hook for all kinds of settings. Uses the same
+7 -1
include/linux/gpio/generic.h
··· 3 3 #ifndef __LINUX_GPIO_GENERIC_H 4 4 #define __LINUX_GPIO_GENERIC_H 5 5 6 + #include <linux/bits.h> 7 + #include <linux/bug.h> 6 8 #include <linux/cleanup.h> 7 - #include <linux/gpio/driver.h> 9 + #include <linux/container_of.h> 10 + #include <linux/errno.h> 8 11 #include <linux/spinlock.h> 12 + #include <linux/types.h> 13 + 14 + #include <linux/gpio/driver.h> 9 15 10 16 struct device; 11 17
-33
include/linux/gpio/machine.h
··· 46 46 struct gpiod_lookup table[]; 47 47 }; 48 48 49 - /** 50 - * struct gpiod_hog - GPIO line hog table 51 - * @chip_label: name of the chip the GPIO belongs to 52 - * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 53 - * @line_name: consumer name for the hogged line 54 - * @lflags: bitmask of gpio_lookup_flags GPIO_* values 55 - * @dflags: GPIO flags used to specify the direction and value 56 - */ 57 - struct gpiod_hog { 58 - struct list_head list; 59 - const char *chip_label; 60 - u16 chip_hwnum; 61 - const char *line_name; 62 - unsigned long lflags; 63 - int dflags; 64 - }; 65 - 66 49 /* 67 50 * Helper for lookup tables with just one single lookup for a device. 68 51 */ ··· 78 95 .flags = _flags, \ 79 96 } 80 97 81 - /* 82 - * Simple definition of a single GPIO hog in an array. 83 - */ 84 - #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \ 85 - (struct gpiod_hog) { \ 86 - .chip_label = _chip_label, \ 87 - .chip_hwnum = _chip_hwnum, \ 88 - .line_name = _line_name, \ 89 - .lflags = _lflags, \ 90 - .dflags = _dflags, \ 91 - } 92 - 93 98 #ifdef CONFIG_GPIOLIB 94 99 void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 95 100 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); 96 101 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); 97 - void gpiod_add_hogs(struct gpiod_hog *hogs); 98 - void gpiod_remove_hogs(struct gpiod_hog *hogs); 99 102 #else /* ! CONFIG_GPIOLIB */ 100 103 static inline 101 104 void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} ··· 89 120 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {} 90 121 static inline 91 122 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} 92 - static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {} 93 - static inline void gpiod_remove_hogs(struct gpiod_hog *hogs) {} 94 123 #endif /* CONFIG_GPIOLIB */ 95 124 96 125 #endif /* __LINUX_GPIO_MACHINE_H */
+1
include/linux/mfd/kempld.h
··· 37 37 #define KEMPLD_SPEC_GET_MINOR(x) (x & 0x0f) 38 38 #define KEMPLD_SPEC_GET_MAJOR(x) ((x >> 4) & 0x0f) 39 39 #define KEMPLD_IRQ_GPIO 0x35 40 + #define KEMPLD_IRQ_GPIO_MASK 0x0f 40 41 #define KEMPLD_IRQ_I2C 0x36 41 42 #define KEMPLD_CFG 0x37 42 43 #define KEMPLD_CFG_GPIO_I2C_MUX (1 << 0)
-38
include/linux/of_gpio.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * OF helpers for the GPIO API 4 - * 5 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 6 - * 7 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 8 - */ 9 - 10 - #ifndef __LINUX_OF_GPIO_H 11 - #define __LINUX_OF_GPIO_H 12 - 13 - #include <linux/compiler.h> 14 - #include <linux/gpio/driver.h> 15 - #include <linux/gpio.h> /* FIXME: Shouldn't be here */ 16 - #include <linux/of.h> 17 - 18 - struct device_node; 19 - 20 - #ifdef CONFIG_OF_GPIO 21 - 22 - extern int of_get_named_gpio(const struct device_node *np, 23 - const char *list_name, int index); 24 - 25 - #else /* CONFIG_OF_GPIO */ 26 - 27 - #include <linux/errno.h> 28 - 29 - /* Drivers may not strictly depend on the GPIO support, so let them link. */ 30 - static inline int of_get_named_gpio(const struct device_node *np, 31 - const char *propname, int index) 32 - { 33 - return -ENOSYS; 34 - } 35 - 36 - #endif /* CONFIG_OF_GPIO */ 37 - 38 - #endif /* __LINUX_OF_GPIO_H */
+9
include/linux/pinctrl/consumer.h
··· 35 35 unsigned int offset); 36 36 int pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset, 37 37 unsigned long config); 38 + int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset, 39 + unsigned long *config); 38 40 39 41 struct pinctrl * __must_check pinctrl_get(struct device *dev); 40 42 void pinctrl_put(struct pinctrl *p); ··· 99 97 100 98 static inline int 101 99 pinctrl_gpio_direction_output(struct gpio_chip *gc, unsigned int offset) 100 + { 101 + return 0; 102 + } 103 + 104 + static inline int 105 + pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset, 106 + unsigned long *config) 102 107 { 103 108 return 0; 104 109 }
+3 -2
tools/testing/selftests/gpio/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh 3 + TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh gpio-cdev-uaf.sh 4 4 TEST_FILES := gpio-mockup-sysfs.sh 5 - TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name 5 + TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name \ 6 + gpio-cdev-uaf 6 7 CFLAGS += -O2 -g -Wall $(KHDR_INCLUDES) 7 8 8 9 include ../lib.mk
+292
tools/testing/selftests/gpio/gpio-cdev-uaf.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * GPIO character device helper for UAF tests. 4 + * 5 + * Copyright 2026 Google LLC 6 + */ 7 + 8 + #include <errno.h> 9 + #include <fcntl.h> 10 + #include <linux/gpio.h> 11 + #include <poll.h> 12 + #include <stdio.h> 13 + #include <stdlib.h> 14 + #include <string.h> 15 + #include <sys/ioctl.h> 16 + #include <sys/stat.h> 17 + #include <sys/types.h> 18 + #include <unistd.h> 19 + 20 + #define CONFIGFS_DIR "/sys/kernel/config/gpio-sim" 21 + #define PROCFS_DIR "/proc" 22 + 23 + static void print_usage(void) 24 + { 25 + printf("usage:\n"); 26 + printf(" gpio-cdev-uaf [chip|handle|event|req] [poll|read|ioctl]\n"); 27 + } 28 + 29 + static int _create_chip(const char *name, int create) 30 + { 31 + char path[64]; 32 + 33 + snprintf(path, sizeof(path), CONFIGFS_DIR "/%s", name); 34 + 35 + if (create) 36 + return mkdir(path, 0755); 37 + else 38 + return rmdir(path); 39 + } 40 + 41 + static int create_chip(const char *name) 42 + { 43 + return _create_chip(name, 1); 44 + } 45 + 46 + static void remove_chip(const char *name) 47 + { 48 + _create_chip(name, 0); 49 + } 50 + 51 + static int _create_bank(const char *chip_name, const char *name, int create) 52 + { 53 + char path[64]; 54 + 55 + snprintf(path, sizeof(path), CONFIGFS_DIR "/%s/%s", chip_name, name); 56 + 57 + if (create) 58 + return mkdir(path, 0755); 59 + else 60 + return rmdir(path); 61 + } 62 + 63 + static int create_bank(const char *chip_name, const char *name) 64 + { 65 + return _create_bank(chip_name, name, 1); 66 + } 67 + 68 + static void remove_bank(const char *chip_name, const char *name) 69 + { 70 + _create_bank(chip_name, name, 0); 71 + } 72 + 73 + static int _enable_chip(const char *name, int enable) 74 + { 75 + char path[64]; 76 + int fd, ret; 77 + 78 + snprintf(path, sizeof(path), CONFIGFS_DIR "/%s/live", name); 79 + 80 + fd = open(path, O_WRONLY); 81 + if (fd == -1) 82 + return fd; 83 + 84 + if (enable) 85 + ret = write(fd, "1", 1); 86 + else 87 + ret = write(fd, "0", 1); 88 + 89 + close(fd); 90 + return ret == 1 ? 0 : -1; 91 + } 92 + 93 + static int enable_chip(const char *name) 94 + { 95 + return _enable_chip(name, 1); 96 + } 97 + 98 + static void disable_chip(const char *name) 99 + { 100 + _enable_chip(name, 0); 101 + } 102 + 103 + static int open_chip(const char *chip_name, const char *bank_name) 104 + { 105 + char path[64], dev_name[32]; 106 + int ret, fd; 107 + 108 + ret = create_chip(chip_name); 109 + if (ret) { 110 + fprintf(stderr, "failed to create chip\n"); 111 + return ret; 112 + } 113 + 114 + ret = create_bank(chip_name, bank_name); 115 + if (ret) { 116 + fprintf(stderr, "failed to create bank\n"); 117 + goto err_remove_chip; 118 + } 119 + 120 + ret = enable_chip(chip_name); 121 + if (ret) { 122 + fprintf(stderr, "failed to enable chip\n"); 123 + goto err_remove_bank; 124 + } 125 + 126 + snprintf(path, sizeof(path), CONFIGFS_DIR "/%s/%s/chip_name", 127 + chip_name, bank_name); 128 + 129 + fd = open(path, O_RDONLY); 130 + if (fd == -1) { 131 + ret = fd; 132 + fprintf(stderr, "failed to open %s\n", path); 133 + goto err_disable_chip; 134 + } 135 + 136 + ret = read(fd, dev_name, sizeof(dev_name) - 1); 137 + close(fd); 138 + if (ret == -1) { 139 + fprintf(stderr, "failed to read %s\n", path); 140 + goto err_disable_chip; 141 + } 142 + dev_name[ret] = '\0'; 143 + if (ret && dev_name[ret - 1] == '\n') 144 + dev_name[ret - 1] = '\0'; 145 + 146 + snprintf(path, sizeof(path), "/dev/%s", dev_name); 147 + 148 + fd = open(path, O_RDWR); 149 + if (fd == -1) { 150 + ret = fd; 151 + fprintf(stderr, "failed to open %s\n", path); 152 + goto err_disable_chip; 153 + } 154 + 155 + return fd; 156 + err_disable_chip: 157 + disable_chip(chip_name); 158 + err_remove_bank: 159 + remove_bank(chip_name, bank_name); 160 + err_remove_chip: 161 + remove_chip(chip_name); 162 + return ret; 163 + } 164 + 165 + static void close_chip(const char *chip_name, const char *bank_name) 166 + { 167 + disable_chip(chip_name); 168 + remove_bank(chip_name, bank_name); 169 + remove_chip(chip_name); 170 + } 171 + 172 + static int test_poll(int fd) 173 + { 174 + struct pollfd pfds; 175 + 176 + pfds.fd = fd; 177 + pfds.events = POLLIN; 178 + pfds.revents = 0; 179 + 180 + if (poll(&pfds, 1, 0) == -1) 181 + return -1; 182 + 183 + return (pfds.revents & ~(POLLHUP | POLLERR)) ? -1 : 0; 184 + } 185 + 186 + static int test_read(int fd) 187 + { 188 + char data; 189 + 190 + if (read(fd, &data, 1) == -1 && errno == ENODEV) 191 + return 0; 192 + return -1; 193 + } 194 + 195 + static int test_ioctl(int fd) 196 + { 197 + if (ioctl(fd, 0, NULL) == -1 && errno == ENODEV) 198 + return 0; 199 + return -1; 200 + } 201 + 202 + int main(int argc, char **argv) 203 + { 204 + int cfd, fd, ret; 205 + int (*test_func)(int); 206 + 207 + if (argc != 3) { 208 + print_usage(); 209 + return EXIT_FAILURE; 210 + } 211 + 212 + if (strcmp(argv[1], "chip") == 0 || 213 + strcmp(argv[1], "event") == 0 || 214 + strcmp(argv[1], "req") == 0) { 215 + if (strcmp(argv[2], "poll") && 216 + strcmp(argv[2], "read") && 217 + strcmp(argv[2], "ioctl")) { 218 + fprintf(stderr, "unknown command: %s\n", argv[2]); 219 + return EXIT_FAILURE; 220 + } 221 + } else if (strcmp(argv[1], "handle") == 0) { 222 + if (strcmp(argv[2], "ioctl")) { 223 + fprintf(stderr, "unknown command: %s\n", argv[2]); 224 + return EXIT_FAILURE; 225 + } 226 + } else { 227 + fprintf(stderr, "unknown command: %s\n", argv[1]); 228 + return EXIT_FAILURE; 229 + } 230 + 231 + if (strcmp(argv[2], "poll") == 0) 232 + test_func = test_poll; 233 + else if (strcmp(argv[2], "read") == 0) 234 + test_func = test_read; 235 + else /* strcmp(argv[2], "ioctl") == 0 */ 236 + test_func = test_ioctl; 237 + 238 + cfd = open_chip("chip", "bank"); 239 + if (cfd == -1) { 240 + fprintf(stderr, "failed to open chip\n"); 241 + return EXIT_FAILURE; 242 + } 243 + 244 + /* Step 1: Hold a FD to the test target. */ 245 + if (strcmp(argv[1], "chip") == 0) { 246 + fd = cfd; 247 + } else if (strcmp(argv[1], "handle") == 0) { 248 + struct gpiohandle_request req = {0}; 249 + 250 + req.lines = 1; 251 + if (ioctl(cfd, GPIO_GET_LINEHANDLE_IOCTL, &req) == -1) { 252 + fprintf(stderr, "failed to get handle FD\n"); 253 + goto err_close_chip; 254 + } 255 + 256 + close(cfd); 257 + fd = req.fd; 258 + } else if (strcmp(argv[1], "event") == 0) { 259 + struct gpioevent_request req = {0}; 260 + 261 + if (ioctl(cfd, GPIO_GET_LINEEVENT_IOCTL, &req) == -1) { 262 + fprintf(stderr, "failed to get event FD\n"); 263 + goto err_close_chip; 264 + } 265 + 266 + close(cfd); 267 + fd = req.fd; 268 + } else { /* strcmp(argv[1], "req") == 0 */ 269 + struct gpio_v2_line_request req = {0}; 270 + 271 + req.num_lines = 1; 272 + if (ioctl(cfd, GPIO_V2_GET_LINE_IOCTL, &req) == -1) { 273 + fprintf(stderr, "failed to get req FD\n"); 274 + goto err_close_chip; 275 + } 276 + 277 + close(cfd); 278 + fd = req.fd; 279 + } 280 + 281 + /* Step 2: Free the chip. */ 282 + close_chip("chip", "bank"); 283 + 284 + /* Step 3: Access the dangling FD to trigger UAF. */ 285 + ret = test_func(fd); 286 + close(fd); 287 + return ret ? EXIT_FAILURE : EXIT_SUCCESS; 288 + err_close_chip: 289 + close(cfd); 290 + close_chip("chip", "bank"); 291 + return EXIT_FAILURE; 292 + }
+63
tools/testing/selftests/gpio/gpio-cdev-uaf.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # Copyright 2026 Google LLC 4 + 5 + BASE_DIR=`dirname $0` 6 + MODULE="gpio-cdev-uaf" 7 + 8 + fail() { 9 + echo "$*" >&2 10 + echo "GPIO $MODULE test FAIL" 11 + exit 1 12 + } 13 + 14 + skip() { 15 + echo "$*" >&2 16 + echo "GPIO $MODULE test SKIP" 17 + exit 4 18 + } 19 + 20 + # Load the gpio-sim module. This will pull in configfs if needed too. 21 + modprobe gpio-sim || skip "unable to load the gpio-sim module" 22 + # Make sure configfs is mounted at /sys/kernel/config. Wait a bit if needed. 23 + for _ in `seq 5`; do 24 + mountpoint -q /sys/kernel/config && break 25 + mount -t configfs none /sys/kernel/config 26 + sleep 0.1 27 + done 28 + mountpoint -q /sys/kernel/config || \ 29 + skip "configfs not mounted at /sys/kernel/config" 30 + 31 + echo "1. GPIO" 32 + 33 + echo "1.1. poll" 34 + $BASE_DIR/gpio-cdev-uaf chip poll || fail "failed to test chip poll" 35 + echo "1.2. read" 36 + $BASE_DIR/gpio-cdev-uaf chip read || fail "failed to test chip read" 37 + echo "1.3. ioctl" 38 + $BASE_DIR/gpio-cdev-uaf chip ioctl || fail "failed to test chip ioctl" 39 + 40 + echo "2. linehandle" 41 + 42 + echo "2.1. ioctl" 43 + $BASE_DIR/gpio-cdev-uaf handle ioctl || fail "failed to test handle ioctl" 44 + 45 + echo "3. lineevent" 46 + 47 + echo "3.1. read" 48 + $BASE_DIR/gpio-cdev-uaf event read || fail "failed to test event read" 49 + echo "3.2. poll" 50 + $BASE_DIR/gpio-cdev-uaf event poll || fail "failed to test event poll" 51 + echo "3.3. ioctl" 52 + $BASE_DIR/gpio-cdev-uaf event ioctl || fail "failed to test event ioctl" 53 + 54 + echo "4. linereq" 55 + 56 + echo "4.1. read" 57 + $BASE_DIR/gpio-cdev-uaf req read || fail "failed to test req read" 58 + echo "4.2. poll" 59 + $BASE_DIR/gpio-cdev-uaf req poll || fail "failed to test req poll" 60 + echo "4.3. ioctl" 61 + $BASE_DIR/gpio-cdev-uaf req ioctl || fail "failed to test req ioctl" 62 + 63 + echo "GPIO $MODULE test PASS"