Skip to content

Commit

Permalink
Merge tag 'gpio-updates-for-v6.9-rc1' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/linux/kernel/git/brgl/linux

Pull gpio updates from Bartosz Golaszewski:
 "The biggest feature is the locking overhaul. Up until now the
  synchronization in the GPIO subsystem was broken. There was a single
  spinlock "protecting" multiple data structures but doing it wrong (as
  evidenced by several places where it would be released when a sleeping
  function was called and then reacquired without checking the protected
  state).

  We tried to use an RW semaphore before but the main issue with GPIO is
  that we have drivers implementing the interfaces in both sleeping and
  non-sleeping ways as well as user-facing interfaces that can be called
  both from process as well as atomic contexts. Both ends converge in
  the same code paths that can use neither spinlocks nor mutexes. The
  only reasonable way out is to use SRCU and go mostly lockless. To that
  end: we add several SRCU structs in relevant places and use them to
  assure consistency between API calls together with atomic reads and
  writes of GPIO descriptor flags where it makes sense.

  This code has spent several weeks in next and has received several
  fixes in the first week or two after which it stabilized nicely. The
  GPIO subsystem is now resilient to providers being suddenly unbound.
  We managed to also remove the existing character device RW semaphore
  and the obsolete global spinlock.

  Other than the locking rework we have one new driver (for Chromebook
  EC), much appreciated documentation improvements from Kent and the
  regular driver improvements, DT-bindings updates and GPIOLIB core
  tweaks.

  Serialization rework:
   - use SRCU to serialize access to the global GPIO device list, to
     GPIO device structs themselves and to GPIO descriptors
   - make the GPIO subsystem resilient to the GPIO providers being
     unbound while the API calls are in progress
   - don't dereference the SRCU-protected chip pointer if the
     information we need can be obtained from the GPIO device structure
   - move some of the information contained in struct gpio_chip to
     struct gpio_device to further reduce the need to dereference the
     former
   - pass the GPIO device struct instead of the GPIO chip to sysfs
     callback to, again, reduce the need for accessing the latter
   - get GPIO descriptors from the GPIO device, not from the chip for
     the same reason
   - allow for mostly lockless operation of the GPIO driver API: assure
     consistency with SRCU and atomic operations
   - remove the global GPIO spinlock
   - remove the character device RW semaphore

  Core GPIOLIB:
   - constify pointers in GPIO API where applicable
   - unify the GPIO counting APIs for ACPI and OF
   - provide a macro for iterating over all GPIOs, not only the ones
     that are requested
   - remove leftover typedefs
   - pass the consumer device to GPIO core in
     devm_fwnode_gpiod_get_index() for improved logging
   - constify the GPIO bus type
   - don't warn about removing GPIO chips with descriptors still held by
     users as we can now handle this situation gracefully
   - remove unused logging helpers
   - unexport functions that are only used internally in the GPIO
     subsystem
   - set the device type (assign the relevant struct device_type) for
     GPIO devices

  New drivers:
   - add the ChromeOS EC GPIO driver

  Driver improvements:
   - allow building gpio-vf610 with COMPILE_TEST as well as disabling it
     in menuconfig (before it was always built for i.MX cofigs)
   - count the number of EICs using the device properties instead of
     hard-coding it in gpio-eic-sprd
   - improve the device naming, extend the debugfs output and add
     lockdep asserts to gpio-sim

  DT bindings:
   - document the 'label' property for gpio-pca9570
   - convert aspeed,ast2400-gpio bindings to DT schema
   - disallow unevaluated properties for gpio-mvebu
   - document a new model in renesas,rcar-gpio

  Documentation:
   - improve the character device kerneldocs in user-space headers
   - add proper documentation for the character device uAPI (both v1 and v2)
   - move the sysfs and gpio-mockup docs into the "obsolete" section
   - improve naming consistency for GPIO terms
   - clarify the line values description for sysfs
   - minor docs improvements
   - improve the driver API contract for setting GPIO direction
   - mark unsafe APIs as deprecated in kerneldocs and suggest
     replacements

  Other:
   - remove an obsolete test from selftests"

* tag 'gpio-updates-for-v6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (79 commits)
  gpio: sysfs: repair export returning -EPERM on 1st attempt
  selftest: gpio: remove obsolete gpio-mockup test
  gpiolib: Deduplicate cleanup for-loop in gpiochip_add_data_with_key()
  dt-bindings: gpio: aspeed,ast2400-gpio: Convert to DT schema
  gpio: acpi: Make acpi_gpio_count() take firmware node as a parameter
  gpio: of: Make of_gpio_get_count() take firmware node as a parameter
  gpiolib: Pass consumer device through to core in devm_fwnode_gpiod_get_index()
  gpio: sim: use for_each_hwgpio()
  gpio: provide for_each_hwgpio()
  gpio: don't warn about removing GPIO chips with active users anymore
  gpio: sim: delimit the fwnode name with a ":" when generating labels
  gpio: sim: add lockdep asserts
  gpio: Add ChromeOS EC GPIO driver
  gpio: constify of_phandle_args in of_find_gpio_device_by_xlate()
  gpio: fix memory leak in gpiod_request_commit()
  gpio: constify opaque pointer "data" in gpio_device_find()
  gpio: cdev: fix a NULL-pointer dereference with DEBUG enabled
  gpio: uapi: clarify default_values being logical
  gpio: sysfs: fix inverted pointer logic
  gpio: don't let lockdep complain about inherently dangerous RCU usage
  ...
  • Loading branch information
Linus Torvalds committed Mar 13, 2024
2 parents 6cdebf6 + 8636f19 commit 69afef4
Show file tree
Hide file tree
Showing 56 changed files with 2,992 additions and 770 deletions.
4 changes: 2 additions & 2 deletions Documentation/ABI/obsolete/sysfs-gpio
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Description:
/label ... (r/o) descriptive, not necessarily unique
/ngpio ... (r/o) number of GPIOs; numbered N to N + (ngpio - 1)

This ABI is deprecated and will be removed after 2020. It is
replaced with the GPIO character device.
This ABI is obsoleted by Documentation/ABI/testing/gpio-cdev and will be
removed after 2020.
9 changes: 5 additions & 4 deletions Documentation/ABI/testing/gpio-cdev
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Description:
The character device files /dev/gpiochip* are the interface
between GPIO chips and userspace.

The ioctl(2)-based ABI is defined and documented in
[include/uapi]<linux/gpio.h>.
The ioctl(2)-based ABI is defined in
[include/uapi]<linux/gpio.h> and documented in
Documentation/userspace-api/gpio/chardev.rst.

The following file operations are supported:

Expand All @@ -17,8 +18,8 @@ Description:
ioctl(2)
Initiate various actions.

See the inline documentation in [include/uapi]<linux/gpio.h>
for descriptions of all ioctls.
See Documentation/userspace-api/gpio/chardev.rst
for a description of all ioctls.

close(2)
Stops and free up the I/O contexts that was associated
Expand Down
8 changes: 8 additions & 0 deletions Documentation/admin-guide/gpio/gpio-mockup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
GPIO Testing Driver
===================

.. note::

This module has been obsoleted by the more flexible gpio-sim.rst.
New developments should use that API and existing developments are
encouraged to migrate as soon as possible.
This module will continue to be maintained but no new features will be
added.

The GPIO Testing Driver (gpio-mockup) provides a way to create simulated GPIO
chips for testing purposes. The lines exposed by these chips can be accessed
using the standard GPIO character device interface as well as manipulated
Expand Down
6 changes: 3 additions & 3 deletions Documentation/admin-guide/gpio/index.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.. SPDX-License-Identifier: GPL-2.0
====
gpio
GPIO
====

.. toctree::
:maxdepth: 1

Character Device Userspace API <../../userspace-api/gpio/chardev>
gpio-aggregator
sysfs
gpio-mockup
gpio-sim
Obsolete APIs <obsolete>

.. only:: subproject and html

Expand Down
13 changes: 13 additions & 0 deletions Documentation/admin-guide/gpio/obsolete.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. SPDX-License-Identifier: GPL-2.0
==================
Obsolete GPIO APIs
==================

.. toctree::
:maxdepth: 1

Character Device Userspace API (v1) <../../userspace-api/gpio/chardev_v1>
Sysfs Interface <../../userspace-api/gpio/sysfs>
Mockup Testing Module <gpio-mockup>

148 changes: 148 additions & 0 deletions Documentation/devicetree/bindings/gpio/aspeed,ast2400-gpio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/gpio/aspeed,ast2400-gpio.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Aspeed GPIO controller

maintainers:
- Andrew Jeffery <andrew@codeconstruct.com.au>

properties:
compatible:
enum:
- aspeed,ast2400-gpio
- aspeed,ast2500-gpio
- aspeed,ast2600-gpio

reg:
maxItems: 1

clocks:
maxItems: 1
description: The clock to use for debounce timings

gpio-controller: true
gpio-line-names:
minItems: 36
maxItems: 232

gpio-ranges: true

"#gpio-cells":
const: 2

interrupts:
maxItems: 1

interrupt-controller: true

"#interrupt-cells":
const: 2

ngpios:
minimum: 36
maximum: 232

required:
- compatible
- reg
- interrupts
- interrupt-controller
- "#interrupt-cells"
- gpio-controller
- "#gpio-cells"

allOf:
- if:
properties:
compatible:
contains:
const: aspeed,ast2400-gpio
then:
properties:
gpio-line-names:
minItems: 220
maxItems: 220
ngpios:
const: 220
- if:
properties:
compatible:
contains:
const: aspeed,ast2500-gpio
then:
properties:
gpio-line-names:
minItems: 232
maxItems: 232
ngpios:
const: 232
- if:
properties:
compatible:
contains:
const: aspeed,ast2600-gpio
then:
properties:
gpio-line-names:
minItems: 36
maxItems: 208
ngpios:
enum: [ 36, 208 ]
required:
- ngpios

additionalProperties: false

examples:
- |
gpio@1e780000 {
compatible = "aspeed,ast2400-gpio";
reg = <0x1e780000 0x1000>;
interrupts = <20>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
};
- |
gpio: gpio@1e780000 {
compatible = "aspeed,ast2500-gpio";
reg = <0x1e780000 0x200>;
interrupts = <20>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
gpio-ranges = <&pinctrl 0 0 232>;
};
- |
#include <dt-bindings/clock/ast2600-clock.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/interrupt-controller/irq.h>
gpio0: gpio@1e780000 {
compatible = "aspeed,ast2600-gpio";
reg = <0x1e780000 0x400>;
clocks = <&syscon ASPEED_CLK_APB2>;
interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
interrupt-controller;
#interrupt-cells = <2>;
#gpio-cells = <2>;
gpio-controller;
gpio-ranges = <&pinctrl 0 0 208>;
ngpios = <208>;
};
gpio1: gpio@1e780800 {
compatible = "aspeed,ast2600-gpio";
reg = <0x1e780800 0x800>;
clocks = <&syscon ASPEED_CLK_APB1>;
interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
gpio-ranges = <&pinctrl 0 208 36>;
ngpios = <36>;
};
39 changes: 0 additions & 39 deletions Documentation/devicetree/bindings/gpio/gpio-aspeed.txt

This file was deleted.

2 changes: 1 addition & 1 deletion Documentation/devicetree/bindings/gpio/gpio-mvebu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ allOf:
required:
- reg

unevaluatedProperties: true
unevaluatedProperties: false

examples:
- |
Expand Down
3 changes: 3 additions & 0 deletions Documentation/devicetree/bindings/gpio/gpio-pca9570.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ properties:
minItems: 4
maxItems: 8

label:
description: A descriptive name for this device.

required:
- compatible
- reg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ properties:
- renesas,gpio-r8a779a0 # R-Car V3U
- renesas,gpio-r8a779f0 # R-Car S4-8
- renesas,gpio-r8a779g0 # R-Car V4H
- renesas,gpio-r8a779h0 # R-Car V4M
- const: renesas,rcar-gen4-gpio # R-Car Gen4

reg:
Expand Down
10 changes: 5 additions & 5 deletions Documentation/driver-api/gpio/consumer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ Use the following calls to access GPIOs from an atomic context::
int gpiod_get_value(const struct gpio_desc *desc);
void gpiod_set_value(struct gpio_desc *desc, int value);

The values are boolean, zero for low, nonzero for high. When reading the value
of an output pin, the value returned should be what's seen on the pin. That
won't always match the specified output value, because of issues including
The values are boolean, zero for inactive, nonzero for active. When reading the
value of an output pin, the value returned should be what's seen on the pin.
That won't always match the specified output value, because of issues including
open-drain signaling and output latencies.

The get/set calls do not return errors because "invalid GPIO" should have been
Expand Down Expand Up @@ -277,11 +277,11 @@ switch their output to a high impedance value. The consumer should not need to
care. (For details read about open drain in driver.rst.)

With this, all the gpiod_set_(array)_value_xxx() functions interpret the
parameter "value" as "asserted" ("1") or "de-asserted" ("0"). The physical line
parameter "value" as "active" ("1") or "inactive" ("0"). The physical line
level will be driven accordingly.

As an example, if the active low property for a dedicated GPIO is set, and the
gpiod_set_(array)_value_xxx() passes "asserted" ("1"), the physical line level
gpiod_set_(array)_value_xxx() passes "active" ("1"), the physical line level
will be driven low.

To summarize::
Expand Down
Loading

0 comments on commit 69afef4

Please sign in to comment.