From: Wadim Mueller <wafgo01@gmail.com>
To: wbg@kernel.org
Cc: krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, Wadim Mueller <wafgo01@gmail.com>
Subject: [PATCH v5 0/3] counter: add GPIO-based counter driver
Date: Sun, 24 May 2026 21:38:43 +0200 [thread overview]
Message-ID: <20260524193846.19216-1-wafgo01@gmail.com> (raw)
In-Reply-To: <20260515153616.157605-1-wafgo01@gmail.com>
This series adds a counter subsystem driver that does quadrature
encoder position tracking with plain GPIO pins and edge interrupts.
Compared to interrupt-cnt.c (pulse-only) it provides full A/B/Index
decoding and exposes the counter sysfs ABI. Target hardware is
low- to medium-speed rotary encoders on SoCs without a free eQEP /
FTM / etc. Benchmark rig: github.com/wafgo/qenc-bench.
Changes in v5
-------------
Following William's v4 review the driver and binding are renamed
from "gpio-quadrature-encoder" to "gpio-counter" -- the name now
reflects what the hardware is, not one of its functions. This
renames the source file, Kconfig symbol, compatible string, binding
file and DT properties (encoder-{a,b}-gpios -> signal-{a,b}-gpios,
encoder-index-gpios -> index-gpios). Out-of-tree users on v1-v4
will need to update their DTs.
Conor's v4 Acked-by on the binding was dropped because of these
rename changes -- a fresh Ack would be appreciated.
Driver fixes from William's review:
- X4 decoder rewritten using the 2-bit Gray-code parity trick
(STATE_CHANGED = pa^pb^ca^cb, DIRECTION via pb^ca) -- no more
16-entry lookup table.
- X1_A / X1_B now count on rising-when-forward / falling-when-
backward in the per-edge ISRs, with the X1 direction caveat
documented in the source.
- action_read holds priv->lock while reading function/direction
and returns from each case directly.
- ceiling_write no longer touches priv->count (matches intel-qep,
ti-eqep, stm32-timer-cnt); the >= guard in the update path
prevents further growth.
- Dropped the redundant functions_list check in function_write
and the !!val rewrite in preset_enable_write.
Sashiko AI [1] flagged seven issues on v4, all addressed:
1. Normalise GPIO reads (a = !!a; b = !!b;) so negative error
codes from gpiod_get_value() cannot index the state tables.
2. priv->enabled tracked under priv->lock -- enable_write is
now idempotent.
3. preset/ceiling TOCTOU closed by moving the check under
priv->lock; index ISR clamps after preset load.
4. probe rejects sleepable GPIOs via gpiod_cansleep().
5. action_read reports RISING/FALLING based on current direction,
matching what the ISR counts on.
6. action_read holds priv->lock (same fix as William's review).
7. IRQF_NO_AUTOEN replaces irq_set_status_flags(IRQ_NOAUTOEN).
MAINTAINERS: section renamed to "GPIO COUNTER DRIVER" and resorted
alphabetically between "GPIO AGGREGATOR" and "GPIO IR Transmitter".
Thanks to William for the patient review and to the Sashiko bot
for the extra finds.
[1] https://sashiko.dev/#/patchset/20260515153616.157605-1-wafgo01@gmail.com?part=2
Wadim Mueller (3):
dt-bindings: counter: add gpio-counter binding
counter: add GPIO-based counter driver
MAINTAINERS: add entry for GPIO counter driver
.../bindings/counter/gpio-counter.yaml | 59 ++
MAINTAINERS | 7 +
drivers/counter/Kconfig | 17 +
drivers/counter/Makefile | 1 +
drivers/counter/gpio-counter.c | 744 ++++++++++++++++++
5 files changed, 828 insertions(+)
create mode 100644 Documentation/devicetree/bindings/counter/gpio-counter.yaml
create mode 100644 drivers/counter/gpio-counter.c
base-commit: 3cd8b194bf3428dfa53120fee47e827a7c495815
--
2.52.0
next prev parent reply other threads:[~2026-05-24 19:39 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 20:07 [PATCH v3 0/3] counter: add GPIO-based quadrature encoder driver Wadim Mueller
2026-05-01 20:07 ` [PATCH v3 1/3] dt-bindings: counter: add gpio-quadrature-encoder binding Wadim Mueller
2026-05-01 20:07 ` [PATCH v3 2/3] counter: add GPIO-based quadrature encoder driver Wadim Mueller
2026-05-04 20:54 ` Krzysztof Kozlowski
2026-05-04 21:15 ` Wadim Mueller
2026-05-15 5:48 ` William Breathitt Gray
2026-05-15 15:28 ` Wadim Mueller
2026-05-01 20:07 ` [PATCH v3 3/3] MAINTAINERS: add entry for GPIO quadrature encoder counter driver Wadim Mueller
2026-05-04 9:36 ` [PATCH v3 0/3] counter: add GPIO-based quadrature encoder driver William Breathitt Gray
2026-05-04 19:37 ` Wadim Mueller
2026-05-06 6:50 ` Wadim Mueller
2026-05-14 13:17 ` William Breathitt Gray
2026-05-15 15:36 ` [PATCH v4 " Wadim Mueller
2026-05-15 15:36 ` [PATCH v4 1/3] dt-bindings: counter: add gpio-quadrature-encoder binding Wadim Mueller
2026-05-15 15:36 ` [PATCH v4 2/3] counter: add GPIO-based quadrature encoder driver Wadim Mueller
2026-05-15 16:14 ` sashiko-bot
2026-05-20 4:45 ` William Breathitt Gray
2026-05-21 0:26 ` William Breathitt Gray
2026-05-24 19:35 ` Wadim Mueller
2026-05-24 19:33 ` Wadim Mueller
2026-05-15 15:36 ` [PATCH v4 3/3] MAINTAINERS: add entry for GPIO quadrature encoder counter driver Wadim Mueller
2026-05-24 19:38 ` Wadim Mueller [this message]
2026-05-24 19:38 ` [PATCH v5 1/3] dt-bindings: counter: add gpio-counter binding Wadim Mueller
2026-05-25 17:09 ` Conor Dooley
2026-05-24 19:38 ` [PATCH v5 2/3] counter: add GPIO-based counter driver Wadim Mueller
2026-05-24 20:14 ` sashiko-bot
2026-05-24 19:38 ` [PATCH v5 3/3] MAINTAINERS: add entry for GPIO " Wadim Mueller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260524193846.19216-1-wafgo01@gmail.com \
--to=wafgo01@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=wbg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox