Skip to content

Commit 8ba3798

Browse files
Ernest Van HoeckeBartosz Golaszewski
authored andcommitted
Documentation: gpio: pca953x: clarify interrupt source detection
There are multiple design tradeoffs and considerations in how the PCA953x driver detects the source(s) of an interrupt. This driver supports PCAL variants with input latching, a feature that is constrained by the fact that the interrupt status and input port registers cannot be read atomically. These limits and the design decisions deserve an in-depth explanation. Update the documentation to clarify these hardware limits and describe how the driver determines pending interrupts, and how it makes use of the PCAL input latching. Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20260107093125.4053468-1-ernestvanhoecke@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent da64eb5 commit 8ba3798

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Documentation/driver-api/gpio/pca953x.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ disabled.
389389
Currently the driver enables the latch for each line with interrupt
390390
enabled.
391391

392+
An interrupt status register records which pins triggered an interrupt.
393+
However, the status register and the input port register must be read
394+
separately; there is no atomic mechanism to read both simultaneously, so races
395+
are possible. Refer to the chapter `Interrupt source detection`_ to understand
396+
the implications of this and how the driver still makes use of the latching
397+
feature.
398+
392399
1. base offset 0x40, bank 2, bank offsets of 2^n
393400
- pcal6408
394401
- pcal6416
@@ -523,6 +530,74 @@ bits drive strength
523530

524531
Currently not supported by the driver.
525532

533+
Interrupt source detection
534+
==========================
535+
536+
When triggered by the GPIO expander's interrupt, the driver determines which
537+
IRQs are pending by reading the input port register.
538+
539+
To be able to filter on specific interrupt events for all compatible devices,
540+
the driver keeps track of the previous input state of the lines, and emits an
541+
IRQ only for the correct edge or level. This system works irrespective of the
542+
number of enabled interrupts. Events will not be missed even if they occur
543+
between the GPIO expander's interrupt and the actual I2C read. Edges could of
544+
course be missed if the related signal level changes back to the value
545+
previously saved by the driver before the I2C read. PCAL variants offer input
546+
latching for that reason.
547+
548+
PCAL input latching
549+
-------------------
550+
551+
The PCAL variants have an input latch and the driver enables this for all
552+
interrupt-enabled lines. The interrupt is then only cleared when the input port
553+
is read out. These variants provide an interrupt status register that records
554+
which pins triggered an interrupt, but the status and input registers cannot be
555+
read atomically. If another interrupt occurs on a different line after the
556+
status register has been read but before the input port register is sampled,
557+
that event will not be reflected in the earlier status snapshot, so relying
558+
solely on the interrupt status register is insufficient.
559+
560+
Thus, the PCAL variants also have to use the existing level-change logic.
561+
562+
For short pulses, the first edge is captured when the input register is read,
563+
but if the signal returns to its previous level before this read, the second
564+
edge is not observed. As a result, successive pulses can produce identical
565+
input values at read time and no level change is detected, causing interrupts
566+
to be missed. Below timing diagram shows this situation where the top signal is
567+
the input pin level and the bottom signal indicates the latched value::
568+
569+
─────┐ ┌──*───────────────┐ ┌──*─────────────────┐ ┌──*───
570+
│ │ . │ │ . │ │ .
571+
│ │ │ │ │ │ │ │ │
572+
└──*──┘ │ └──*──┘ │ └──*──┘ │
573+
Input │ │ │ │ │ │
574+
▼ │ ▼ │ ▼ │
575+
IRQ │ IRQ │ IRQ │
576+
. . .
577+
─────┐ .┌──────────────┐ .┌────────────────┐ .┌──
578+
│ │ │ │ │ │
579+
│ │ │ │ │ │
580+
└────────*┘ └────────*┘ └────────*┘
581+
Latched │ │ │
582+
▼ ▼ ▼
583+
READ 0 READ 0 READ 0
584+
NO CHANGE NO CHANGE
585+
586+
To deal with this, events indicated by the interrupt status register are merged
587+
with events detected through the existing level-change logic. As a result:
588+
589+
- short pulses, whose second edges are invisible, are detected via the
590+
interrupt status register, and
591+
- interrupts that occur between the status and input reads are still
592+
caught by the generic level-change logic.
593+
594+
Note that this is still best-effort: the status and input registers are read
595+
separately, and short pulses on other lines may occur in between those reads.
596+
Such pulses can still be latched as an interrupt without leaving an observable
597+
level change at read time, and may not be attributable to a specific edge. This
598+
does not reduce detection compared to the generic path, but reflects inherent
599+
atomicity limitations.
600+
526601
Datasheets
527602
==========
528603

0 commit comments

Comments
 (0)