Skip to content

Commit b3c0ecc

Browse files
committed
Merge tag 'gpio-updates-for-v6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio updates from Bartosz Golaszewski: "The majority of added lines are two new modules: the GPIO virtual consumer module that improves our ability to add automated tests for the kernel API and the "sloppy" logic analyzer module that uses the GPIO API to implement a coarse-grained debugging tool for useful for remote development. Other than that we have the usual assortment of various driver extensions, improvements to the core GPIO code, DT-bindings and other documentation updates as well as an extension to the interrupt simulator: GPIOLIB core: - rework kfifo handling rework in the character device code - improve the labeling of GPIOs requested as interrupts and show more info on interrupt-only GPIOs in debugfs - remove unused APIs - unexport interfaces that are only used from the core GPIO code - drop the return value from gpiochip_set_desc_names() as it cannot fail - move a string array definition out of a header and into a specific compilation unit - convert the last user of gpiochip_get_desc() other than GPIO core to using a safer alternative - use array_index_nospec() where applicable New drivers: - add a "virtual GPIO consumer" module that allows requesting GPIOs from actual hardware and driving tests of the in-kernel GPIO API from user-space over debugfs - add a GPIO-based "sloppy" logic analyzer module useful for "first glance" debugging on remote boards Driver improvements: - add support for a new model to gpio-pca953x - lock GPIOs as interrupts in gpio-sim when the lines are requested as irqs via the simulator domain + some other minor improvements - improve error reporting in gpio-syscon - convert gpio-ath79 to using dynamic GPIO base and range - use pcibios_err_to_errno() for converting PCIBIOS error codes to errno vaues in gpio-amd8111 and gpio-rdc321x - allow building gpio-brcmstb for the BCM2835 architecture DT bindings: - convert DT bindings for lsi,zevio, mpc8xxx, and atmel to DT schema - document new properties for aspeed,gpio, fsl,qoriq-gpio and gpio-vf610 - document new compatibles for pca953x and fsl,qoriq-gpio Documentation: - document stricter behavior of the GPIO character device uAPI with regards to reconfiguring requested line without direction set - clarify the effect of the active-low flag on line values and edges - remove documentation for the legacy GPIO API in order to stop tempting people to use it - document the preference for using pread() for reading edge events in the sysfs API Other: - add an extended initializer to the interrupt simulator allowing to specify a number of callbacks callers can use to be notified about irqs being requested and released" * tag 'gpio-updates-for-v6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (41 commits) gpio: mc33880: Convert comma to semicolon gpio: virtuser: actually use the "trimmed" local variable dt-bindings: gpio: convert Atmel GPIO to json-schema gpio: virtuser: new virtual testing driver for the GPIO API dt-bindings: gpio: vf610: Allow gpio-line-names to be set gpio: sim: lock GPIOs as interrupts when they are requested genirq/irq_sim: add an extended irq_sim initializer dt-bindings: gpio: fsl,qoriq-gpio: Add compatible string fsl,ls1046a-gpio gpiolib: unexport gpiochip_get_desc() gpio: add sloppy logic analyzer using polling Documentation: gpio: Reconfiguration with unset direction (uAPI v2) Documentation: gpio: Reconfiguration with unset direction (uAPI v1) dt-bindings: gpio: fsl,qoriq-gpio: add common property gpio-line-names gpio: ath79: convert to dynamic GPIO base allocation pinctrl: da9062: replace gpiochip_get_desc() with gpio_device_get_desc() gpiolib: put gpio_suffixes in a single compilation unit Documentation: gpio: Clarify effect of active low flag on line edges Documentation: gpio: Clarify effect of active low flag on line values gpiolib: Remove data-less gpiochip_add() function gpio: sim: use devm_mutex_init() ...
2 parents 3f32ab1 + dfda97e commit b3c0ecc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3187
-2123
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
.. SPDX-License-Identifier: GPL-2.0-only
2+
3+
Virtual GPIO Consumer
4+
=====================
5+
6+
The virtual GPIO Consumer module allows users to instantiate virtual devices
7+
that request GPIOs and then control their behavior over debugfs. Virtual
8+
consumer devices can be instantiated from device-tree or over configfs.
9+
10+
A virtual consumer uses the driver-facing GPIO APIs and allows to cover it with
11+
automated tests driven by user-space. The GPIOs are requested using
12+
``gpiod_get_array()`` and so we support multiple GPIOs per connector ID.
13+
14+
Creating GPIO consumers
15+
-----------------------
16+
17+
The gpio-consumer module registers a configfs subsystem called
18+
``'gpio-virtuser'``. For details of the configfs filesystem, please refer to
19+
the configfs documentation.
20+
21+
The user can create a hierarchy of configfs groups and items as well as modify
22+
values of exposed attributes. Once the consumer is instantiated, this hierarchy
23+
will be translated to appropriate device properties. The general structure is:
24+
25+
**Group:** ``/config/gpio-virtuser``
26+
27+
This is the top directory of the gpio-consumer configfs tree.
28+
29+
**Group:** ``/config/gpio-consumer/example-name``
30+
31+
**Attribute:** ``/config/gpio-consumer/example-name/live``
32+
33+
**Attribute:** ``/config/gpio-consumer/example-name/dev_name``
34+
35+
This is a directory representing a GPIO consumer device.
36+
37+
The read-only ``dev_name`` attribute exposes the name of the device as it will
38+
appear in the system on the platform bus. This is useful for locating the
39+
associated debugfs directory under
40+
``/sys/kernel/debug/gpio-virtuser/$dev_name``.
41+
42+
The ``'live'`` attribute allows to trigger the actual creation of the device
43+
once it's fully configured. The accepted values are: ``'1'`` to enable the
44+
virtual device and ``'0'`` to disable and tear it down.
45+
46+
Creating GPIO lookup tables
47+
---------------------------
48+
49+
Users can create a number of configfs groups under the device group:
50+
51+
**Group:** ``/config/gpio-consumer/example-name/con_id``
52+
53+
The ``'con_id'`` directory represents a single GPIO lookup and its value maps
54+
to the ``'con_id'`` argument of the ``gpiod_get()`` function. For example:
55+
``con_id`` == ``'reset'`` maps to the ``reset-gpios`` device property.
56+
57+
Users can assign a number of GPIOs to each lookup. Each GPIO is a sub-directory
58+
with a user-defined name under the ``'con_id'`` group.
59+
60+
**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/key``
61+
62+
**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/offset``
63+
64+
**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/drive``
65+
66+
**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/pull``
67+
68+
**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/active_low``
69+
70+
**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/transitory``
71+
72+
This is a group describing a single GPIO in the ``con_id-gpios`` property.
73+
74+
For virtual consumers created using configfs we use machine lookup tables so
75+
this group can be considered as a mapping between the filesystem and the fields
76+
of a single entry in ``'struct gpiod_lookup'``.
77+
78+
The ``'key'`` attribute represents either the name of the chip this GPIO
79+
belongs to or the GPIO line name. This depends on the value of the ``'offset'``
80+
attribute: if its value is >= 0, then ``'key'`` represents the label of the
81+
chip to lookup while ``'offset'`` represents the offset of the line in that
82+
chip. If ``'offset'`` is < 0, then ``'key'`` represents the name of the line.
83+
84+
The remaining attributes map to the ``'flags'`` field of the GPIO lookup
85+
struct. The first two take string values as arguments:
86+
87+
**``'drive'``:** ``'push-pull'``, ``'open-drain'``, ``'open-source'``
88+
**``'pull'``:** ``'pull-up'``, ``'pull-down'``, ``'pull-disabled'``, ``'as-is'``
89+
90+
``'active_low'`` and ``'transitory'`` are boolean attributes.
91+
92+
Activating GPIO consumers
93+
-------------------------
94+
95+
Once the confiuration is complete, the ``'live'`` attribute must be set to 1 in
96+
order to instantiate the consumer. It can be set back to 0 to destroy the
97+
virtual device. The module will synchronously wait for the new simulated device
98+
to be successfully probed and if this doesn't happen, writing to ``'live'`` will
99+
result in an error.
100+
101+
Device-tree
102+
-----------
103+
104+
Virtual GPIO consumers can also be defined in device-tree. The compatible string
105+
must be: ``"gpio-virtuser"`` with at least one property following the
106+
standardized GPIO pattern.
107+
108+
An example device-tree code defining a virtual GPIO consumer:
109+
110+
.. code-block :: none
111+
112+
gpio-virt-consumer {
113+
compatible = "gpio-virtuser";
114+
115+
foo-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>, <&gpio1 2 0>;
116+
bar-gpios = <&gpio0 6 0>;
117+
};
118+
119+
Controlling virtual GPIO consumers
120+
----------------------------------
121+
122+
Once active, the device will export debugfs attributes for controlling GPIO
123+
arrays as well as each requested GPIO line separately. Let's consider the
124+
following device property: ``foo-gpios = <&gpio0 0 0>, <&gpio0 4 0>;``.
125+
126+
The following debugfs attribute groups will be created:
127+
128+
**Group:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo/``
129+
130+
This is the group that will contain the attributes for the entire GPIO array.
131+
132+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo/values``
133+
134+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo/values_atomic``
135+
136+
Both attributes allow to read and set arrays of GPIO values. User must pass
137+
exactly the number of values that the array contains in the form of a string
138+
containing zeroes and ones representing inactive and active GPIO states
139+
respectively. In this example: ``echo 11 > values``.
140+
141+
The ``values_atomic`` attribute works the same as ``values`` but the kernel
142+
will execute the GPIO driver callbacks in interrupt context.
143+
144+
**Group:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/``
145+
146+
This is a group that represents a single GPIO with ``$index`` being its offset
147+
in the array.
148+
149+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/consumer``
150+
151+
Allows to set and read the consumer label of the GPIO line.
152+
153+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/debounce``
154+
155+
Allows to set and read the debounce period of the GPIO line.
156+
157+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/direction``
158+
159+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/direction_atomic``
160+
161+
These two attributes allow to set the direction of the GPIO line. They accept
162+
"input" and "output" as values. The atomic variant executes the driver callback
163+
in interrupt context.
164+
165+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/interrupts``
166+
167+
If the line is requested in input mode, writing ``1`` to this attribute will
168+
make the module listen for edge interrupts on the GPIO. Writing ``0`` disables
169+
the monitoring. Reading this attribute returns the current number of registered
170+
interrupts (both edges).
171+
172+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/value``
173+
174+
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/value_atomic``
175+
176+
Both attributes allow to read and set values of individual requested GPIO lines.
177+
They accept the following values: ``1`` and ``0``.

Documentation/admin-guide/gpio/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ GPIO
1010
Character Device Userspace API <../../userspace-api/gpio/chardev>
1111
gpio-aggregator
1212
gpio-sim
13+
gpio-virtuser
1314
Obsolete APIs <obsolete>
1415

1516
.. only:: subproject and html
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=============================================
4+
Linux Kernel GPIO based sloppy logic analyzer
5+
=============================================
6+
7+
:Author: Wolfram Sang
8+
9+
Introduction
10+
============
11+
12+
This document briefly describes how to run the GPIO based in-kernel sloppy
13+
logic analyzer running on an isolated CPU.
14+
15+
The sloppy logic analyzer will utilize a few GPIO lines in input mode on a
16+
system to rapidly sample these digital lines, which will, if the Nyquist
17+
criteria is met, result in a time series log with approximate waveforms as they
18+
appeared on these lines. One way to use it is to analyze external traffic
19+
connected to these GPIO lines with wires (i.e. digital probes), acting as a
20+
common logic analyzer.
21+
22+
Another feature is to snoop on on-chip peripherals if the I/O cells of these
23+
peripherals can be used in GPIO input mode at the same time as they are being
24+
used as inputs or outputs for the peripheral. That means you could e.g. snoop
25+
I2C traffic without any wiring (if your hardware supports it). In the pin
26+
control subsystem such pin controllers are called "non-strict": a certain pin
27+
can be used with a certain peripheral and as a GPIO input line at the same
28+
time.
29+
30+
Note that this is a last resort analyzer which can be affected by latencies,
31+
non-deterministic code paths and non-maskable interrupts. It is called 'sloppy'
32+
for a reason. However, for e.g. remote development, it may be useful to get a
33+
first view and aid further debugging.
34+
35+
Setup
36+
=====
37+
38+
Your kernel must have CONFIG_DEBUG_FS and CONFIG_CPUSETS enabled. Ideally, your
39+
runtime environment does not utilize cpusets otherwise, then isolation of a CPU
40+
core is easiest. If you do need cpusets, check that helper script for the
41+
sloppy logic analyzer does not interfere with your other settings.
42+
43+
Tell the kernel which GPIOs are used as probes. For a Device Tree based system,
44+
you need to use the following bindings. Because these bindings are only for
45+
debugging, there is no official schema::
46+
47+
i2c-analyzer {
48+
compatible = "gpio-sloppy-logic-analyzer";
49+
probe-gpios = <&gpio6 21 GPIO_OPEN_DRAIN>, <&gpio6 4 GPIO_OPEN_DRAIN>;
50+
probe-names = "SCL", "SDA";
51+
};
52+
53+
Note that you must provide a name for every GPIO specified. Currently a
54+
maximum of 8 probes are supported. 32 are likely possible but are not
55+
implemented yet.
56+
57+
Usage
58+
=====
59+
60+
The logic analyzer is configurable via files in debugfs. However, it is
61+
strongly recommended to not use them directly, but to use the script
62+
``tools/gpio/gpio-sloppy-logic-analyzer``. Besides checking parameters more
63+
extensively, it will isolate the CPU core so you will have the least
64+
disturbance while measuring.
65+
66+
The script has a help option explaining the parameters. For the above DT
67+
snippet which analyzes an I2C bus at 400kHz on a Renesas Salvator-XS board, the
68+
following settings are used: The isolated CPU shall be CPU1 because it is a big
69+
core in a big.LITTLE setup. Because CPU1 is the default, we don't need a
70+
parameter. The bus speed is 400kHz. So, the sampling theorem says we need to
71+
sample at least at 800kHz. However, falling edges of both signals in an I2C
72+
start condition happen faster, so we need a higher sampling frequency, e.g.
73+
``-s 1500000`` for 1.5MHz. Also, we don't want to sample right away but wait
74+
for a start condition on an idle bus. So, we need to set a trigger to a falling
75+
edge on SDA while SCL stays high, i.e. ``-t 1H+2F``. Last is the duration, let
76+
us assume 15ms here which results in the parameter ``-d 15000``. So,
77+
altogether::
78+
79+
gpio-sloppy-logic-analyzer -s 1500000 -t 1H+2F -d 15000
80+
81+
Note that the process will return you back to the prompt but a sub-process is
82+
still sampling in the background. Unless this has finished, you will not find a
83+
result file in the current or specified directory. For the above example, we
84+
will then need to trigger I2C communication::
85+
86+
i2cdetect -y -r <your bus number>
87+
88+
Result is a .sr file to be consumed with PulseView or sigrok-cli from the free
89+
`sigrok`_ project. It is a zip file which also contains the binary sample data
90+
which may be consumed by other software. The filename is the logic analyzer
91+
instance name plus a since-epoch timestamp.
92+
93+
.. _sigrok: https://sigrok.org/

Documentation/dev-tools/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Documentation/dev-tools/testing-overview.rst
3232
kunit/index
3333
ktap
3434
checkuapi
35+
gpio-sloppy-logic-analyzer
3536

3637

3738
.. only:: subproject and html

Documentation/devicetree/bindings/gpio/aspeed,sgpio.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ properties:
3333

3434
gpio-controller: true
3535

36+
# Each SGPIO is represented as a pair of input and output GPIOs
37+
gpio-line-names:
38+
minItems: 160
39+
maxItems: 256
40+
3641
'#gpio-cells':
3742
const: 2
3843

@@ -41,6 +46,9 @@ properties:
4146

4247
interrupt-controller: true
4348

49+
'#interrupt-cells':
50+
const: 2
51+
4452
clocks:
4553
maxItems: 1
4654

@@ -55,6 +63,7 @@ required:
5563
- '#gpio-cells'
5664
- interrupts
5765
- interrupt-controller
66+
- '#interrupt-cells'
5867
- ngpios
5968
- clocks
6069
- bus-frequency
@@ -72,6 +81,7 @@ examples:
7281
reg = <0x1e780200 0x0100>;
7382
clocks = <&syscon ASPEED_CLK_APB>;
7483
interrupt-controller;
84+
#interrupt-cells = <2>;
7585
ngpios = <80>;
7686
bus-frequency = <12000000>;
7787
};

0 commit comments

Comments
 (0)